﻿# V1118\. Excessive file permissions can lead to vulnerabilities\. Consider restricting file permissions\.

Excessive file permissions indicate security risks and may lead to vulnerabilities\.

The analyzer checks the following system calls for excessive permissions: [`open`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html), [`creat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/creat.html), [`openat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html), [`chmod`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html), [`fchmod`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html), [`fchmodat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html), [`mkdir`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html), [`mkdirat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html), [`mkfifo`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifo.html), [`mkfifoat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkfifo.html), [`mknod`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html), [`mknodat`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html), [`mq_open`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html), and [`sem_open`](https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html)\.

The example:

```cpp
void foo(int param)
{
  int perms = 0777;
  int fd = open("/path/to/file", O_CREAT | O_RDONLY, perms);
  if (fd < 0) return;
 
  // some work

  close(fd);
}
```

The code uses the `open` system call to open a file and process the information it contains\. If the file does not exist, it will be created via the `O_CREAT` flag in the second argument and have permissions specified by the number in the third argument\. In this case, the `0777` mask allows any user to read, write, or execute this file, which can lead to vulnerabilities\.

To fix the error, modify the permission mask:

```cpp
void foo(int param)
{
  int perms = 0644;
  int fd = open("/path/to/file", O_CREAT | O_RDONLY, perms);
  if (fd < 0) return;
 
  // some work

  close(fd);
}
```