diff options
author | Todd C. Miller <Todd.Miller@courtesan.com> | 2014-01-13 11:11:26 -0700 |
---|---|---|
committer | Todd C. Miller <Todd.Miller@courtesan.com> | 2014-01-13 11:11:26 -0700 |
commit | f147866164fe453ca8e6e63e3afc6023a2a0ba4e (patch) | |
tree | 859c3c63f91bb9ca7db54c434b83e32a228c9614 /src | |
parent | db2d2cdfae74cde96c881fb918029e71eafc2cd1 (diff) | |
download | sudo-f147866164fe453ca8e6e63e3afc6023a2a0ba4e.tar.gz |
Fix strtonum() usage when parsing /proc/self/stat on Linux.
Bug #630
Diffstat (limited to 'src')
-rw-r--r-- | src/ttyname.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/ttyname.c b/src/ttyname.c index 4a95b625d..1996a250a 100644 --- a/src/ttyname.c +++ b/src/ttyname.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com> + * Copyright (c) 2012-2014 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -441,10 +441,12 @@ get_process_ttyname(void) if (len != -1) { /* Field 7 is the tty dev (0 if no tty) */ char *cp = line; + char *ep = line; const char *errstr; - int field = 1; - while (*cp != '\0') { - if (*cp++ == ' ') { + int field = 0; + while (*++ep != '\0') { + if (*ep == ' ') { + *ep = '\0'; if (++field == 7) { dev_t tdev = strtonum(cp, INT_MIN, INT_MAX, &errstr); if (errstr) { @@ -455,6 +457,7 @@ get_process_ttyname(void) tty = sudo_ttyname_dev(tdev); break; } + cp = ep + 1; } } } |