Linux: silence UBSAN implicit conversions

pgrp and session might be -1

linux/LinuxProcessList.c:312:20: runtime error: implicit conversion from type 'unsigned long' of value 18446744073709551615 (64-bit, unsigned) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:312:20 in
linux/LinuxProcessList.c:314:23: runtime error: implicit conversion from type 'unsigned long' of value 18446744073709551615 (64-bit, unsigned) to type 'unsigned int' changed the value to 4294967295 (32-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/LinuxProcessList.c:314:23 in
This commit is contained in:
Christian Göttsche 2021-01-27 15:12:15 +01:00 committed by BenBE
parent 1014e897a7
commit 7bfa466abe
2 changed files with 4 additions and 4 deletions

View File

@ -76,10 +76,10 @@ typedef struct Process_ {
pid_t tgid;
/* Process group identifier */
unsigned int pgrp;
int pgrp;
/* Session identifier */
unsigned int session;
int session;
/* Foreground group identifier of the controlling terminal */
int tpgid;

View File

@ -316,11 +316,11 @@ static bool LinuxProcessList_readStatFile(Process* process, openat_arg_t procFd,
location += 1;
/* (5) pgrp - %d */
process->pgrp = strtoul(location, &location, 10);
process->pgrp = strtol(location, &location, 10);
location += 1;
/* (6) session - %d */
process->session = strtoul(location, &location, 10);
process->session = strtol(location, &location, 10);
location += 1;
/* (7) tty_nr - %d */