Unverified Commit e97dfb8c by 2xsec Committed by Christian Brauner

coverity: #1438231

Dereference after null check Signed-off-by: 's avatar2xsec <dh48.jeong@samsung.com>
parent eae95dc7
...@@ -1558,7 +1558,7 @@ static bool get_uid_gid(const char *user, uid_t *uid, gid_t *gid) ...@@ -1558,7 +1558,7 @@ static bool get_uid_gid(const char *user, uid_t *uid, gid_t *gid)
if (!pwentp) { if (!pwentp) {
if (ret == 0) if (ret == 0)
mysyslog(LOG_ERR, mysyslog(LOG_ERR,
"Could not find matched password record\n", NULL); "Could not find matched password record\n", NULL);
free(buf); free(buf);
return false; return false;
...@@ -1610,6 +1610,7 @@ static uint32_t *cg_cpumask(char *buf, size_t nbits) ...@@ -1610,6 +1610,7 @@ static uint32_t *cg_cpumask(char *buf, size_t nbits)
char *range = strchr(token, '-'); char *range = strchr(token, '-');
if (range) if (range)
end = strtoul(range + 1, NULL, 0); end = strtoul(range + 1, NULL, 0);
if (!(start <= end)) { if (!(start <= end)) {
free(bitarr); free(bitarr);
return NULL; return NULL;
...@@ -1678,9 +1679,11 @@ static char *cg_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits) ...@@ -1678,9 +1679,11 @@ static char *cg_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
free_string_list(cpulist); free_string_list(cpulist);
return NULL; return NULL;
} }
must_append_string(&cpulist, numstr); must_append_string(&cpulist, numstr);
} }
} }
return string_join(",", (const char **)cpulist, false); return string_join(",", (const char **)cpulist, false);
} }
...@@ -1703,10 +1706,12 @@ static ssize_t cg_get_max_cpus(char *cpulist) ...@@ -1703,10 +1706,12 @@ static ssize_t cg_get_max_cpus(char *cpulist)
else if (c1 < c2) else if (c1 < c2)
c1 = c2; c1 = c2;
if (!c1)
return -1;
/* If the above logic is correct, c1 should always hold a valid string /* If the above logic is correct, c1 should always hold a valid string
* here. * here.
*/ */
errno = 0; errno = 0;
cpus = strtoul(c1, NULL, 0); cpus = strtoul(c1, NULL, 0);
if (errno != 0) if (errno != 0)
...@@ -1718,10 +1723,12 @@ static ssize_t cg_get_max_cpus(char *cpulist) ...@@ -1718,10 +1723,12 @@ static ssize_t cg_get_max_cpus(char *cpulist)
static ssize_t write_nointr(int fd, const void* buf, size_t count) static ssize_t write_nointr(int fd, const void* buf, size_t count)
{ {
ssize_t ret; ssize_t ret;
again: again:
ret = write(fd, buf, count); ret = write(fd, buf, count);
if (ret < 0 && errno == EINTR) if (ret < 0 && errno == EINTR)
goto again; goto again;
return ret; return ret;
} }
...@@ -1733,16 +1740,19 @@ static int write_to_file(const char *filename, const void* buf, size_t count, bo ...@@ -1733,16 +1740,19 @@ static int write_to_file(const char *filename, const void* buf, size_t count, bo
fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0666); fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0666);
if (fd < 0) if (fd < 0)
return -1; return -1;
ret = write_nointr(fd, buf, count); ret = write_nointr(fd, buf, count);
if (ret < 0) if (ret < 0)
goto out_error; goto out_error;
if ((size_t)ret != count) if ((size_t)ret != count)
goto out_error; goto out_error;
if (add_newline) { if (add_newline) {
ret = write_nointr(fd, "\n", 1); ret = write_nointr(fd, "\n", 1);
if (ret != 1) if (ret != 1)
goto out_error; goto out_error;
} }
close(fd); close(fd);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment