These are 2 hex digits each with a ':' between them in the kernel.
---
 toys/pending/lsof.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
From 1c6c67e62cea41ef2c1fad90dc7ce92cf6056521 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <e...@google.com>
Date: Sat, 25 Sep 2021 18:53:23 -0700
Subject: [PATCH] lsof: explicit size for device major:minor buffer.

These are 2 hex digits each with a ':' between them in the kernel.
---
 toys/pending/lsof.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/toys/pending/lsof.c b/toys/pending/lsof.c
index 2ab4177a..7d209bc2 100644
--- a/toys/pending/lsof.c
+++ b/toys/pending/lsof.c
@@ -330,10 +330,10 @@ static void visit_maps(struct proc_info *pi)
 {
   FILE *fp;
   unsigned long long offset;
-  char device[10];
   long inode;
-  char *line = NULL;
+  char *line = NULL, device[6];
   size_t line_length = 0;
+  struct file_info *fi;
 
   snprintf(toybuf, sizeof(toybuf), "/proc/%d/maps", pi->pid);
   fp = fopen(toybuf, "r");
@@ -342,10 +342,8 @@ static void visit_maps(struct proc_info *pi)
   while (getline(&line, &line_length, fp) > 0) {
     int name_pos;
 
-    if (sscanf(line, "%*x-%*x %*s %llx %s %ld %n",
+    if (sscanf(line, "%*x-%*x %*s %llx %5s %ld %n",
                &offset, device, &inode, &name_pos) >= 3) {
-      struct file_info *fi;
-
       // Ignore non-file maps.
       if (inode == 0 || !strcmp(device, "00:00")) continue;
       // TODO: show unique maps even if they have a non-zero offset?
-- 
2.33.0.685.g46640cef36-goog

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to