Skip to content

Commit cc8c43c

Browse files
committed
Format ttydev as (signed) long long, not unsigned.
Now that we parse ttydev as a long long it makes more sense to format it the same way. This completely avoids the sign extension issue on systems where dev_t is signed.
1 parent 6b90acb commit cc8c43c

File tree

5 files changed

+7
-58
lines changed

5 files changed

+7
-58
lines changed

config.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,9 +1293,6 @@
12931293
/* Define to 1 if you want sudo to set $HOME in shell mode. */
12941294
#undef SHELL_SETS_HOME
12951295

1296-
/* The size of 'dev_t', as computed by sizeof. */
1297-
#undef SIZEOF_DEV_T
1298-
12991296
/* The size of 'id_t', as computed by sizeof. */
13001297
#undef SIZEOF_ID_T
13011298

configure

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21003,41 +21003,6 @@ printf "%s\n" "$ac_cv_sizeof_long_long" >&6; }
2100321003
printf "%s\n" "#define SIZEOF_LONG_LONG $ac_cv_sizeof_long_long" >>confdefs.h
2100421004

2100521005

21006-
# The cast to long int works around a bug in the HP C Compiler
21007-
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
21008-
# declarations like 'int a3[[(sizeof (unsigned char)) >= 0]];'.
21009-
# This bug is HP SR number 8606223364.
21010-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking size of dev_t" >&5
21011-
printf %s "checking size of dev_t... " >&6; }
21012-
if test ${ac_cv_sizeof_dev_t+y}
21013-
then :
21014-
printf %s "(cached) " >&6
21015-
else case e in #(
21016-
e) if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (dev_t))" "ac_cv_sizeof_dev_t" "$ac_includes_default"
21017-
then :
21018-
21019-
else case e in #(
21020-
e) if test "$ac_cv_type_dev_t" = yes; then
21021-
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
21022-
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
21023-
as_fn_error 77 "cannot compute sizeof (dev_t)
21024-
See 'config.log' for more details" "$LINENO" 5; }
21025-
else
21026-
ac_cv_sizeof_dev_t=0
21027-
fi ;;
21028-
esac
21029-
fi
21030-
;;
21031-
esac
21032-
fi
21033-
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_dev_t" >&5
21034-
printf "%s\n" "$ac_cv_sizeof_dev_t" >&6; }
21035-
21036-
21037-
21038-
printf "%s\n" "#define SIZEOF_DEV_T $ac_cv_sizeof_dev_t" >>confdefs.h
21039-
21040-
2104121006
# The cast to long int works around a bug in the HP C Compiler
2104221007
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
2104321008
# declarations like 'int a3[[(sizeof (unsigned char)) >= 0]];'.

configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2507,7 +2507,6 @@ SUDO_SOCK_SA_LEN
25072507
SUDO_SOCK_SIN_LEN
25082508
AC_CHECK_SIZEOF([long])
25092509
AC_CHECK_SIZEOF([long long])
2510-
AC_CHECK_SIZEOF([dev_t])
25112510
AC_CHECK_SIZEOF([id_t])
25122511
AC_CHECK_SIZEOF([time_t])
25132512
AC_CHECK_SIZEOF([uid_t])

src/regress/ttyname/check_ttyname.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 2013-2020, 2022 Todd C. Miller <Todd.Miller@sudo.ws>
4+
* Copyright (c) 2013-2020, 2022, 2024 Todd C. Miller <Todd.Miller@sudo.ws>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -88,8 +88,7 @@ main(int argc, char *argv[])
8888
/* Lookup tty name using kernel info if possible. */
8989
ttydev = get_process_ttyname(pathbuf, sizeof(pathbuf));
9090
if (ttydev != (dev_t)-1) {
91-
char numbuf[STRLEN_MAX_UNSIGNED(unsigned long long) + 1];
92-
unsigned long long ullval;
91+
char numbuf[STRLEN_MAX_SIGNED(long long) + 1];
9392
const char *errstr;
9493
dev_t newdev;
9594

@@ -98,20 +97,15 @@ main(int argc, char *argv[])
9897

9998
/* Check that we can format a dev_t as a string and parse it. */
10099
ntests++;
101-
#if SIZEOF_DEV_T == SIZEOF_LONG
102-
ullval = (unsigned long)ttydev;
103-
#else
104-
ullval = (unsigned long long)ttydev;
105-
#endif
106-
(void)snprintf(numbuf, sizeof(numbuf), "%llu", ullval);
100+
(void)snprintf(numbuf, sizeof(numbuf), "%lld", (long long)ttydev);
107101
newdev = sudo_strtonum(numbuf, LLONG_MIN, LLONG_MAX, &errstr);
108102
if (errstr != NULL) {
109103
printf("%s: FAIL unable to parse device number %s: %s",
110104
getprogname(), numbuf, errstr);
111105
errors++;
112106
} else if (ttydev != newdev) {
113-
printf("%s: FAIL device mismatch for %s, %s != %llu",
114-
getprogname(), pathbuf, numbuf, ullval);
107+
printf("%s: FAIL device mismatch for %s, %s != %lld",
108+
getprogname(), pathbuf, numbuf, (long long)ttydev);
115109
errors++;
116110
}
117111
}

src/sudo.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 2009-2023 Todd C. Miller <Todd.Miller@sudo.ws>
4+
* Copyright (c) 2009-2024 Todd C. Miller <Todd.Miller@sudo.ws>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -620,13 +620,7 @@ get_user_info(struct user_details *ud)
620620

621621
ttydev = get_process_ttyname(path, sizeof(path));
622622
if (ttydev != (dev_t)-1) {
623-
int len;
624-
#if SIZEOF_DEV_T == SIZEOF_LONG
625-
len = asprintf(&info[++i], "ttydev=%lu", (unsigned long)ttydev);
626-
#else
627-
len = asprintf(&info[++i], "ttydev=%llu", (unsigned long long)ttydev);
628-
#endif
629-
if (len == -1)
623+
if (asprintf(&info[++i], "ttydev=%lld", (long long)ttydev) == -1)
630624
goto oom;
631625
info[++i] = sudo_new_key_val("tty", path);
632626
if (info[i] == NULL)

0 commit comments

Comments
 (0)