View | Details | Raw Unified | Return to bug 1039361
Collapse All | Expand All

(-)sudo-1.8.20/src/ttyname.c (-21 / +30 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 * Copyright (c) 2012-2016 Todd C. Miller <Todd.Miller@courtesan.com>
2
 * Copyright (c) 2012-2017 Todd C. Miller <Todd.Miller@courtesan.com>
3
 *
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
5
 * purpose with or without fee is hereby granted, provided that the above
Lines 159-164 Link Here
159
159
160
static char *ignore_devs[] = {
160
static char *ignore_devs[] = {
161
    "/dev/fd/",
161
    "/dev/fd/",
162
    "/dev/mqueue/",
163
    "/dev/shm/",
162
    "/dev/stdin",
164
    "/dev/stdin",
163
    "/dev/stdout",
165
    "/dev/stdout",
164
    "/dev/stderr",
166
    "/dev/stderr",
Lines 493-520 Link Here
493
	len = getline(&line, &linesize, fp);
495
	len = getline(&line, &linesize, fp);
494
	fclose(fp);
496
	fclose(fp);
495
	if (len != -1) {
497
	if (len != -1) {
496
	    /* Field 7 is the tty dev (0 if no tty) */
498
	    /*
497
	    char *cp = line;
499
	     * Field 7 is the tty dev (0 if no tty).
498
	    char *ep = line;
500
	     * Since the process name at field 2 "(comm)" may include spaces,
499
	    const char *errstr;
501
	     * start at the last ')' found.
500
	    int field = 0;
502
	     */
501
	    while (*++ep != '\0') {
503
	    char *cp = strrchr(line, ')');
502
		if (*ep == ' ') {
504
	    if (cp != NULL) {
503
		    *ep = '\0';
505
		char *ep = cp;
504
		    if (++field == 7) {
506
		const char *errstr;
505
			dev_t tdev = strtonum(cp, INT_MIN, INT_MAX, &errstr);
507
		int field = 1;
506
			if (errstr) {
508
507
			    sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
509
		while (*++ep != '\0') {
508
				"%s: tty device %s: %s", path, cp, errstr);
510
		    if (*ep == ' ') {
511
			*ep = '\0';
512
			if (++field == 7) {
513
			    dev_t tdev = strtonum(cp, INT_MIN, INT_MAX, &errstr);
514
			    if (errstr) {
515
				sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
516
				    "%s: tty device %s: %s", path, cp, errstr);
517
			    }
518
			    if (tdev > 0) {
519
				errno = serrno;
520
				ret = sudo_ttyname_dev(tdev, name, namelen);
521
				goto done;
522
			    }
523
			    break;
509
			}
524
			}
510
			if (tdev > 0) {
525
			cp = ep + 1;
511
			    errno = serrno;
512
			    ret = sudo_ttyname_dev(tdev, name, namelen);
513
			    goto done;
514
			}
515
			break;
516
		    }
526
		    }
517
		    cp = ep + 1;
518
		}
527
		}
519
	    }
528
	    }
520
	}
529
	}

Return to bug 1039361