mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-30 05:48:18 +00:00
Avoid sign extension when assigning the value of tty_nr in
/proc/self/stat on Linux. It is an unsigned int value that is printed as a signed int but dev_t is unsigned long long. We need to cast to unsigned int before assigning to a dev_t.
This commit is contained in:
parent
e1e2162dcf
commit
26d9043bf4
@ -496,12 +496,19 @@ get_process_ttyname(char *name, size_t namelen)
|
|||||||
if (*ep == ' ') {
|
if (*ep == ' ') {
|
||||||
*ep = '\0';
|
*ep = '\0';
|
||||||
if (++field == 7) {
|
if (++field == 7) {
|
||||||
dev_t tdev = strtonum(cp, INT_MIN, INT_MAX, &errstr);
|
int tty_nr = strtonum(cp, INT_MIN, INT_MAX, &errstr);
|
||||||
if (errstr) {
|
if (errstr) {
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
"%s: tty device %s: %s", path, cp, errstr);
|
"%s: tty device %s: %s", path, cp, errstr);
|
||||||
}
|
}
|
||||||
if (tdev > 0) {
|
if (tty_nr != 0) {
|
||||||
|
/*
|
||||||
|
* Avoid sign extension when assigning tdev.
|
||||||
|
* tty_nr in /proc/self/stat is printed as a
|
||||||
|
* signed int but the actual device number is an
|
||||||
|
* unsigned int and dev_t is unsigned long long.
|
||||||
|
*/
|
||||||
|
dev_t tdev = (unsigned int)tty_nr;
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
ret = sudo_ttyname_dev(tdev, name, namelen);
|
ret = sudo_ttyname_dev(tdev, name, namelen);
|
||||||
goto done;
|
goto done;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user