summaryrefslogtreecommitdiffstats
path: root/src/Hooks
diff options
context:
space:
mode:
authorKarel Klic <kklic@redhat.com>2009-10-30 23:47:27 +0100
committerKarel Klic <kklic@redhat.com>2009-10-30 23:47:27 +0100
commitd0962176b885a32b1c5aecd5ac3c0d23447c3d09 (patch)
treea876da5cefe940264b97d35e80b9cd3a7ef7e64a /src/Hooks
parent0843e750bce39df0e69e4962b3c7f98294d0739b (diff)
parent276a9017d63445dd322f9a93ff34e67cbdf97dc9 (diff)
downloadabrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.tar.gz
abrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.tar.xz
abrt-d0962176b885a32b1c5aecd5ac3c0d23447c3d09.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src/Hooks')
-rw-r--r--src/Hooks/CCpp.cpp31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index e6768a60..1c152e6c 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -54,32 +54,41 @@ static char* get_cmdline(pid_t pid)
char path[PATH_MAX];
char cmdline[COMMAND_LINE_SIZE];
snprintf(path, sizeof(path), "/proc/%u/cmdline", (int)pid);
- int dst = 0;
+ int idx = 0;
int fd = open(path, O_RDONLY);
if (fd >= 0)
{
int len = read(fd, cmdline, sizeof(cmdline) - 1);
- if (len >= 0)
+ close(fd);
+
+ if (len > 0)
{
- int src = 0;
- while (src < len)
+ /* In Linux, there is always one trailing NUL byte,
+ * prevent it from being replaced by space below.
+ */
+ if (cmdline[len - 1] == '\0')
+ len--;
+
+ while (idx < len)
{
- char ch = cmdline[src++];
+ unsigned char ch = cmdline[idx];
if (ch == '\0')
{
- cmdline[dst++] = ' ';
+ cmdline[idx++] = ' ';
}
- /* TODO: maybe just ch >= ' '? */
- else if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
+ else if (ch >= ' ' && ch <= 0x7e)
{
- cmdline[dst++] = ch;
+ cmdline[idx++] = ch;
+ }
+ else
+ {
+ cmdline[idx++] = '?';
}
}
}
- close(fd);
}
- cmdline[dst] = '\0';
+ cmdline[idx] = '\0';
return xstrdup(cmdline);
}