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 | 931185d7d98c632b75f530b50d0277fcbcd4bf20 (patch) | |
tree | 27672b13e22ffb9b7840460906a052095e9e5baa | |
parent | 1107243ecc32279bdaeb29970190a850bf1e1b0d (diff) | |
download | sudo-931185d7d98c632b75f530b50d0277fcbcd4bf20.tar.gz |
Fix strtonum() usage when parsing /proc/self/stat on Linux.SUDO_1_8_9p3
Bug #630
-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; } } } |