prevent out-of-bounds read/write if proc arg happens to be > 1024
This commit is contained in:
parent
af16d018ec
commit
ea6b08a70f
|
@ -746,7 +746,7 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
int alen;
|
int alen;
|
||||||
char *arg;
|
char *arg;
|
||||||
|
|
||||||
if ((nread = pread(fd, buffer, sizeof(buffer), (off_t)argvp[n])) <= 0) {
|
if ((nread = pread(fd, buffer, sizeof(buffer)-1, (off_t)argvp[n])) <= 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
if (argvp != argvb) {
|
if (argvp != argvb) {
|
||||||
free(argvp);
|
free(argvp);
|
||||||
|
@ -754,7 +754,8 @@ int sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||||
sigar_proc_args_destroy(sigar, procargs);
|
sigar_proc_args_destroy(sigar, procargs);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
/* chances of arg > 1024 are slim, but just incase. */
|
||||||
|
buffer[nread] = '\0';
|
||||||
alen = strlen(buffer)+1;
|
alen = strlen(buffer)+1;
|
||||||
arg = malloc(alen);
|
arg = malloc(alen);
|
||||||
memcpy(arg, buffer, alen);
|
memcpy(arg, buffer, alen);
|
||||||
|
|
Loading…
Reference in New Issue