[augeas-devel] [PATCH] Fix escaping (internal.c)

James Antill james.antill at redhat.com
Wed May 21 18:19:31 UTC 2008


# HG changeset patch
# User james at and.org
# Date 1211393347 14400
# Node ID 3501e5535b70717230a15d4f219d2dbb7bca247e
# Parent  8a1ea0e2a3ca69213b9f550749f50dd96a07db97
 Fix escaping strings that end in \
 Fix escaping of unprintable bytes

diff --git a/src/internal.c b/src/internal.c
--- a/src/internal.c
+++ b/src/internal.c
@@ -152,7 +152,7 @@
     char *result, *t;
     int i;
 
-    if (len > strlen(s))
+    if (len < 0 || len > strlen(s))
         len = strlen(s);
 
     size = 0;
@@ -182,7 +182,7 @@
         cnt = strlen(text);
 
     for (int i=0; i < cnt; i++) {
-        if (strchr(escape_chars, text[i]) != NULL)
+        if (text[i] && (strchr(escape_chars, text[i]) != NULL))
             len += 2;  /* Escaped as '\x' */
         else if (! isprint(text[i]))
             len += 4;  /* Escaped as '\ooo' */
@@ -193,11 +193,12 @@
     e = esc;
     for (int i=0; i < cnt; i++) {
         char *p;
-        if ((p = strchr(escape_chars, text[i])) != NULL) {
+        if (text[i] && ((p = strchr(escape_chars, text[i])) != NULL)) {
             *e++ = '\\';
             *e++ = escape_names[p - escape_chars];
         } else if (! isprint(text[i])) {
             sprintf(e, "\\%03o", text[i]);
+            e += 4;
         } else {
             *e++ = text[i];
         }

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080521/2604a1fd/attachment.sig>


More information about the augeas-devel mailing list