Skip to content
Snippets Groups Projects
Commit 9e6032a2 authored by Morris Jette's avatar Morris Jette
Browse files

Fix possible invalid memory references

Make sure strings are NULL terminated.
Prolems reported by Coverity
parent 5eb15c8b
No related branches found
No related tags found
No related merge requests found
...@@ -84,7 +84,7 @@ enqueue_nag_req(int fd, int rank, char *key) ...@@ -84,7 +84,7 @@ enqueue_nag_req(int fd, int rank, char *key)
req = xmalloc(sizeof(nag_req_t)); req = xmalloc(sizeof(nag_req_t));
req->fd = fd; req->fd = fd;
req->rank = rank; req->rank = rank;
strncpy(req->key, key, PMI2_MAX_KEYLEN); strncpy(req->key, key, (PMI2_MAX_KEYLEN - 1)); /* Insure NULL at end */
/* insert in the head */ /* insert in the head */
req->next = nag_req_list; req->next = nag_req_list;
......
...@@ -332,7 +332,7 @@ extern pid_t find_ancestor(pid_t process, char *process_name) ...@@ -332,7 +332,7 @@ extern pid_t find_ancestor(pid_t process, char *process_name)
int fd; int fd;
long pid, ppid; long pid, ppid;
rbuf = xmalloc(4096); rbuf = xmalloc_nz(4096);
pid = ppid = (long)process; pid = ppid = (long)process;
do { do {
if (ppid <= 1) { if (ppid <= 1) {
...@@ -345,6 +345,7 @@ extern pid_t find_ancestor(pid_t process, char *process_name) ...@@ -345,6 +345,7 @@ extern pid_t find_ancestor(pid_t process, char *process_name)
pid = 0; pid = 0;
break; break;
} }
memset(rbuf, 0, 4096);
buf_used = read(fd, rbuf, 4096); buf_used = read(fd, rbuf, 4096);
if ((buf_used <= 0) || (buf_used >= 4096)) { if ((buf_used <= 0) || (buf_used >= 4096)) {
close(fd); close(fd);
......
...@@ -230,12 +230,12 @@ int slurm_set_cpuset(char *base, char *path, pid_t pid, size_t size, ...@@ -230,12 +230,12 @@ int slurm_set_cpuset(char *base, char *path, pid_t pid, size_t size,
* "mems" must be set before any tasks can be added. */ * "mems" must be set before any tasks can be added. */
snprintf(file_path, sizeof(file_path), "%s/%smems", snprintf(file_path, sizeof(file_path), "%s/%smems",
base, cpuset_prefix); base, cpuset_prefix);
memset(mstr, 0, sizeof(mstr));
fd = open(file_path, O_RDONLY); fd = open(file_path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
error("open(%s): %m", file_path); error("open(%s): %m", file_path);
} else { } else {
rc = read(fd, mstr, sizeof(mstr)); memset(mstr, 0, sizeof(mstr));
rc = read(fd, mstr, sizeof(mstr)-1); /* Insure NULL at end */
close(fd); close(fd);
if (rc < 1) { if (rc < 1) {
error("read(%s): %m", file_path); error("read(%s): %m", file_path);
...@@ -306,7 +306,8 @@ int slurm_get_cpuset(char *path, pid_t pid, size_t size, cpu_set_t *mask) ...@@ -306,7 +306,8 @@ int slurm_get_cpuset(char *path, pid_t pid, size_t size, cpu_set_t *mask)
error("open(%s): %m", file_path); error("open(%s): %m", file_path);
return SLURM_ERROR; return SLURM_ERROR;
} }
rc = read(fd, mstr, sizeof(mstr)); memset(mstr, 0, sizeof(mstr));
rc = read(fd, mstr, sizeof(mstr)-1); /* Insure NULL at end */
close(fd); close(fd);
if (rc < 1) { if (rc < 1) {
error("read(%s): %m", file_path); error("read(%s): %m", file_path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment