[Pkg-gnupg-commit] [libassuan] 54/437: 2002-10-31 Neal H. Walfield <neal at g10code.de>

Eric Dorland eric at moszumanska.debian.org
Fri May 22 05:33:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository libassuan.

commit e638b3342a80ce6a01e44b2c47e51c51bb42e5c5
Author: Neal Walfield <neal at walfield.org>
Date:   Thu Oct 31 16:52:21 2002 +0000

    2002-10-31  Neal H. Walfield  <neal at g10code.de>
    
    	* assuan-util.c: Include <ctype.h>.
    	(_assuan_log_print_buffer): Elide the magic numbers preferring the
    	standard isfoo functions.  Use putc_unlocked where possible.
    	(_assuan_log_sanitized_string): Rewrite to use putc_unlocked and
    	the isfoo functions.
---
 src/ChangeLog     |  8 +++++
 src/assuan-util.c | 94 ++++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 74 insertions(+), 28 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 7fe3c40..552a9c8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2002-10-31  Neal H. Walfield  <neal at g10code.de>
+
+	* assuan-util.c: Include <ctype.h>.
+	(_assuan_log_print_buffer): Elide the magic numbers preferring the
+	standard isfoo functions.  Use putc_unlocked where possible.
+	(_assuan_log_sanitized_string): Rewrite to use putc_unlocked and
+	the isfoo functions.
+
 2002-09-05  Neal H. Walfield  <neal at g10code.de>
 
 	* assuan-defs.h (_assuan_read_wrapper): Depreciated.
diff --git a/src/assuan-util.c b/src/assuan-util.c
index 24a9799..76f7f06 100644
--- a/src/assuan-util.c
+++ b/src/assuan-util.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <ctype.h>
 
 #include "assuan-defs.h"
 
@@ -127,6 +128,8 @@ assuan_end_confidential (ASSUAN_CONTEXT ctx)
     }
 }
 
+/* Dump a possibly binary string (used for debugging).  Distinguish
+   ascii text from binary and print it accordingly.  */
 void
 _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
 {
@@ -134,26 +137,31 @@ _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
   int n;
 
   for (n=length,s=buffer; n; n--, s++)
-    {
-      if (*s < ' ' || (*s >= 0x7f && *s <= 0xa0))
-        break;
-    }
+    if  (!isascii (*s) || iscntrl (*s) || !isprint (*s))
+      break;
+
   s = buffer;
   if (!n && *s != '[')
     fwrite (buffer, length, 1, fp);
   else
     {
-      putc ('[', fp);
+#ifdef HAVE_FLOCKFILE
+      flockfile (fp);
+#endif
+      putc_unlocked ('[', fp);
       for (n=0; n < length; n++, s++)
           fprintf (fp, " %02x", *s);
-      putc (' ', fp);
-      putc (']', fp);
+      putc_unlocked (' ', fp);
+      putc_unlocked (']', fp);
+#ifdef HAVE_FUNLOCKFILE
+      funlockfile (fp);
+#endif
     }
 }
 
 
-/* print a user supplied string after filtering out potential bad
-   characters*/
+/* Log a user supplied string.  Escapes non-printable before
+   printing.  */
 void
 _assuan_log_sanitized_string (const char *string)
 {
@@ -164,29 +172,59 @@ _assuan_log_sanitized_string (const char *string)
   FILE *fp = stderr;
 #endif
 
+  if (! *s)
+    return;
+
+#ifdef HAVE_FLOCKFILE
+  flockfile (fp);
+#endif
+
   for (; *s; s++)
     {
-      if (*s < 0x20 || (*s >= 0x7f && *s <= 0xa0))
-        {
-          putc ('\\', fp);
-          if (*s == '\n')
-            putc ('n', fp);
-          else if (*s == '\r')
-            putc ('r', fp);
-          else if (*s == '\f')
-            putc ('f', fp);
-          else if (*s == '\v')
-            putc ('v', fp);
-          else if (*s == '\b')
-            putc ('b', fp);
-          else if (!*s)
-            putc ('0', fp);
-          else
-            fprintf (fp, "x%02x", *s );
+      int c = 0;
+
+      switch (*s)
+	{
+	case '\r':
+	  c = 'r';
+	  break;
+
+	case '\n':
+	  c = 'n';
+	  break;
+
+	case '\f':
+	  c = 'f';
+	  break;
+
+	case '\v':
+	  c = 'v';
+	  break;
+
+	case '\b':
+	  c = 'b';
+	  break;
+
+	default:
+	  if (isascii (*s) && isprint (*s))
+	    putc_unlocked (*s, fp);
+	  else
+	    {
+	      putc_unlocked ('\\', fp);
+	      fprintf (fp, "x%02x", *s);
+	    }
+	}
+
+      if (c)
+	{
+	  putc_unlocked ('\\', fp);
+	  putc_unlocked (c, fp);
 	}
-      else
-        putc (*s, fp);
     }
+
+#ifdef HAVE_FUNLOCKFILE
+  funlockfile (fp);
+#endif
 }
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git



More information about the Pkg-gnupg-commit mailing list