From 8399d035cca082d01ea49929c9628ee9dd45a5d8 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Sat, 23 Aug 2008 18:04:42 +0000 Subject: [PATCH] (procfs_system_process_attributes): Fix portability problems. --- src/ChangeLog | 5 +++++ src/process.c | 35 +++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9f24bff2a1a..90989ae98e3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2008-08-23 Andreas Schwab + + * process.c (procfs_system_process_attributes): Fix use of + uninitialized variables. + 2008-08-23 Eli Zaretskii * emacs.c (main) [MSDOS]: Call syms_of_xmenu. diff --git a/src/process.c b/src/process.c index dd41ba5e25a..6bb652a974f 100644 --- a/src/process.c +++ b/src/process.c @@ -7246,10 +7246,10 @@ procfs_system_process_attributes (pid) char procbuf[1025], *p, *q; int fd; ssize_t nread; - char cmd[PATH_MAX]; + const char *cmd; char *cmdline = NULL; size_t cmdsize; - int c; + unsigned char c; int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount; unsigned long long utime, stime, cutime, cstime, start; long priority, nice, rss; @@ -7277,7 +7277,7 @@ procfs_system_process_attributes (pid) uid_eint = uid; attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs); BLOCK_INPUT; - pw = (struct passwd *) getpwuid (uid); + pw = getpwuid (uid); UNBLOCK_INPUT; if (pw) attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs); @@ -7286,7 +7286,7 @@ procfs_system_process_attributes (pid) gid_eint = gid; attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs); BLOCK_INPUT; - gr = (struct group *) getgrgid (gid); + gr = getgrgid (gid); UNBLOCK_INPUT; if (gr) attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs); @@ -7300,18 +7300,25 @@ procfs_system_process_attributes (pid) procbuf[nread] = '\0'; p = procbuf; - p = strchr (p, '(') + 1; - q = strchr (p, ')'); - /* comm */ - if (q > p) + cmd = NULL; + p = strchr (p, '('); + if (p != NULL) { - memcpy (cmd, p, q - p); - cmd[q - p] = '\0'; + q = strrchr (p + 1, ')'); + /* comm */ + if (q != NULL) + { + cmd = p + 1; + cmdsize = q - cmd; + } + } + if (cmd == NULL) + { + cmd = "???"; + cmdsize = 3; } - else - strcpy (cmd, "???"); /* Command name is encoded in locale-coding-system; decode it. */ - cmd_str = make_unibyte_string (cmd, q ? q - p : 3); + cmd_str = make_unibyte_string (cmd, cmdsize); decoded_cmd = code_convert_string_norecord (cmd_str, Vlocale_coding_system, 0); attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs); @@ -7412,7 +7419,7 @@ procfs_system_process_attributes (pid) fd = emacs_open (fn, O_RDONLY, 0); if (fd >= 0) { - for (cmdsize = 0; emacs_read (fd, (char *)&c, 1) == 1; cmdsize++) + for (cmdsize = 0; emacs_read (fd, &c, 1) == 1; cmdsize++) { if (isspace (c) || c == '\\') cmdsize++; /* for later quoting, see below */ -- 2.39.2