Skip to content

Commit f48c166

Browse files
[lldb][Linux] Parse, but don't store "comm" from /proc/stat file (#100387)
As reported in #89710, the %s code used for `comm` could and probably does, overflow the buffer. Likely we haven't seen it cause problems because the following data is overwritten right afterwards. Also scanf isn't a great choice here as this `comm` can include many characters that might trip up %s. We don't actually use `comm`, so parse but don't store it so we're not overflowing anything.
1 parent dc1c00f commit f48c166

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lldb/source/Host/linux/Host.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ enum class ProcessState {
5151
Zombie,
5252
};
5353

54-
constexpr int task_comm_len = 16;
55-
5654
struct StatFields {
5755
::pid_t pid = LLDB_INVALID_PROCESS_ID;
58-
char comm[task_comm_len];
56+
// comm
5957
char state;
6058
::pid_t ppid = LLDB_INVALID_PROCESS_ID;
6159
::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
@@ -100,8 +98,8 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
10098
StatFields stat_fields;
10199
if (sscanf(
102100
Rest.data(),
103-
"%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
104-
&stat_fields.pid, stat_fields.comm, &stat_fields.state,
101+
"%d %*s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
102+
&stat_fields.pid, /* comm, */ &stat_fields.state,
105103
&stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
106104
&stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,
107105
&stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt,

0 commit comments

Comments
 (0)