aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysdep.c
diff options
context:
space:
mode:
authorPaul Eggert <[email protected]>2011-07-28 18:16:54 -0700
committerPaul Eggert <[email protected]>2011-07-28 18:16:54 -0700
commitfe6442b1151a0f4021181e968479459f50df63f1 (patch)
tree5c009bab54a101bf8ea6fa1845e53a73e23a6f4e /src/sysdep.c
parent5f2ab479cdd2e76862e80e37b9c0825471af8d4c (diff)
* sysdep.c: Integer and memory overflow issues.
(system_process_attributes): Use ptrdiff_t, not int, for command line length. Do not attempt to address one before the beginning of an array, as that's not portable.
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 4bd1f54b9e..57fff94f55 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2640,7 +2640,7 @@ system_process_attributes (Lisp_Object pid)
ssize_t nread;
const char *cmd = NULL;
char *cmdline = NULL;
- size_t cmdsize = 0, cmdline_size;
+ ptrdiff_t cmdsize = 0, cmdline_size;
unsigned char c;
int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount;
unsigned long long u_time, s_time, cutime, cstime, start;
@@ -2822,8 +2822,10 @@ system_process_attributes (Lisp_Object pid)
if (fd >= 0)
{
char ch;
- for (cmdline_size = 0; emacs_read (fd, &ch, 1) == 1; cmdline_size++)
+ for (cmdline_size = 0; cmdline_size < STRING_BYTES_BOUND; cmdline_size++)
{
+ if (emacs_read (fd, &ch, 1) != 1)
+ break;
c = ch;
if (isspace (c) || c == '\\')
cmdline_size++; /* for later quoting, see below */
@@ -2844,7 +2846,7 @@ system_process_attributes (Lisp_Object pid)
nread = 0;
}
/* We don't want trailing null characters. */
- for (p = cmdline + nread - 1; p > cmdline && !*p; p--)
+ for (p = cmdline + nread; p > cmdline + 1 && !p[-1]; p--)
nread--;
for (p = cmdline; p < cmdline + nread; p++)
{