(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/file-dotlock.c) |
| |
| 91 | | | static pid_t read_local_pid(const char *lock_path) |
| 92 | | | { |
| 93 | | | char buf[512], *host; |
| 94 | | | int fd; |
| 95 | | | ssize_t ret; |
| 96 | | | pid_t pid; |
| 97 | | | |
| 98 | | | fd = open(lock_path, O_RDONLY); |
| 99 | | | if (fd == -1) |
| 100 | | | return -1; |
| 101 | | | |
| 102 | | | |
| 103 | | | ret = read(fd, buf, sizeof(buf)-1); |
| 104 | | | (void)close(fd); |
| 105 | | | if (ret <= 0) |
| 106 | | | return -1; |
| 107 | | | |
| 108 | | | |
| 109 | | | if (buf[ret-1] == '\n') |
| 110 | | | ret--; |
| 111 | | | buf[ret] = '\0'; |
| 112 | | | |
| 113 | | | |
| 114 | | | host = strchr(buf, ':'); |
| 115 | | | if (host == NULL) |
| 116 | | | return -1; |
| 117 | | | *host++ = '\0'; |
| 118 | | | |
| 119 | | | |
| 120 | | | if (strcmp(host, my_hostname) != 0) |
Redundant Condition
strcmp(host, my_hostname) != 0 always evaluates to true. This may be because: - There is a constant assignment to one or more of the variables involved.
- An earlier conditional statement has already ensured that strcmp(host, my_hostname) != 0 cannot be false.
- A crashing bug occurs on every path where strcmp(host, my_hostname) != 0 could have evaluated to false. Look for a preceding Null Pointer Dereference or Division By Zero warning.
|
|
| 121 | | | return -1; |
| 122 | | | |
| 123 | | | if (!is_numeric(buf, '\0')) |
| 124 | | | return -1; |
| 125 | | | pid = (pid_t)strtoul(buf, NULL, 0); |
| 126 | | | if (pid <= 0) |
| 127 | | | return -1; |
| 128 | | | return pid; |
| 129 | | | } |
| |