[Lldb-commits] [lldb] [lldb] Correct format specifier for sscanf to prevent buffer overflow (NFC) (PR #94783)

Shivam Gupta via lldb-commits lldb-commits at lists.llvm.org
Sat Jul 6 01:57:20 PDT 2024


https://github.com/xgupta updated https://github.com/llvm/llvm-project/pull/94783

>From 17d39d89ee723881063ecbea19caaa6806e4e095 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Sat, 15 Jun 2024 23:57:03 +0530
Subject: [PATCH 1/2] Resolved merge conflict

---
 lldb/source/Host/linux/Host.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 5545f9ef4d70e6..8a38947d4b665f 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -100,7 +100,7 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
   StatFields stat_fields;
   if (sscanf(
           Rest.data(),
-          "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
+          "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
           &stat_fields.pid, stat_fields.comm, &stat_fields.state,
           &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
           &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,

>From d84106a138040dc4e680ec82306969f8ff7ec01d Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivma98.tkg at gmail.com>
Date: Sat, 6 Jul 2024 10:57:08 +0200
Subject: [PATCH 2/2] run clang-format

---
 lldb/source/Host/linux/Host.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 8a38947d4b665f..b5fa266da1d3bf 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -98,16 +98,16 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo &ProcessInfo,
   if (Rest.empty())
     return false;
   StatFields stat_fields;
-  if (sscanf(
-          Rest.data(),
-          "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld",
-          &stat_fields.pid, stat_fields.comm, &stat_fields.state,
-          &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
-          &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,
-          &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt,
-          &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime,
-          &stat_fields.cutime, &stat_fields.cstime,
-          &stat_fields.realtime_priority, &stat_fields.priority) < 0) {
+  if (sscanf(Rest.data(),
+             "%d %15s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu %ld %ld %ld "
+             "%ld",
+             &stat_fields.pid, stat_fields.comm, &stat_fields.state,
+             &stat_fields.ppid, &stat_fields.pgrp, &stat_fields.session,
+             &stat_fields.tty_nr, &stat_fields.tpgid, &stat_fields.flags,
+             &stat_fields.minflt, &stat_fields.cminflt, &stat_fields.majflt,
+             &stat_fields.cmajflt, &stat_fields.utime, &stat_fields.stime,
+             &stat_fields.cutime, &stat_fields.cstime,
+             &stat_fields.realtime_priority, &stat_fields.priority) < 0) {
     return false;
   }
 



More information about the lldb-commits mailing list