[PINENTRY PATCH 1/3] core: Clean up command line extraction.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sun Feb 5 08:22:26 CET 2017


* pinentry/pinentry.c (get_cmdline): Avoid trailing space, and return
NULL when no bytes were read from /proc.

Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
 pinentry/pinentry.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pinentry/pinentry.c b/pinentry/pinentry.c
index 517a033..8cf712d 100644
--- a/pinentry/pinentry.c
+++ b/pinentry/pinentry.c
@@ -410,14 +410,16 @@ get_cmdline (unsigned long pid)
       fclose (fp);
       return NULL;
     }
-  /* Arguments are delimites by Nuls.  We should do proper quoting but
+  fclose (fp);
+  if (n == 0)
+    return NULL;
+  /* Arguments are delimited by Nuls.  We should do proper quoting but
    * that can be a bit complicated, thus we simply replace the Nuls by
    * spaces.  */
   for (i=0; i < n; i++)
-    if (!buffer[i])
+    if (!buffer[i] && i < n-1)
       buffer[i] = ' ';
   buffer[i] = 0; /* Make sure the last byte is the string terminator.  */
-  fclose (fp);
 
   return strdup (buffer);
 }
-- 
2.11.0




More information about the Gnupg-devel mailing list