]> granicus.if.org Git - strace/commitdiff
2007-11-01 Roland McGrath <roland@redhat.com>
authorRoland McGrath <roland@redhat.com>
Thu, 1 Nov 2007 23:53:59 +0000 (23:53 +0000)
committerRoland McGrath <roland@redhat.com>
Thu, 1 Nov 2007 23:53:59 +0000 (23:53 +0000)
* util.c (string_quote): Return nonzero if the string was unterminated.
(printstr): Use that value instead of just our own test.
(printpathn): Likewise.
Fixes RH#358241.

util.c

diff --git a/util.c b/util.c
index 461b9dac80ffc25f9cb33d6053cda63fdcb3be6c..70011e2171c23b973c27f0ab21764d0df864d262 100644 (file)
--- a/util.c
+++ b/util.c
@@ -407,7 +407,7 @@ unsigned long uid;
 
 static char path[MAXPATHLEN + 1];
 
-static void
+static int
 string_quote(const char *instr, char *outstr, int len, int size)
 {
        const unsigned char *ustr = (const unsigned char *) instr;
@@ -419,6 +419,8 @@ string_quote(const char *instr, char *outstr, int len, int size)
        else if (xflag) {
                for (i = 0; i < size; ++i) {
                        c = ustr[i];
+                       if (len < 0 && i == size - 2 && c != '\0')
+                               ++i;
                        if (len < 0 && c == '\0')
                                break;
                        if (!isprint(c) && !isspace(c)) {
@@ -441,6 +443,8 @@ string_quote(const char *instr, char *outstr, int len, int size)
        } else {
                for (i = 0; i < size; ++i) {
                        c = ustr[i];
+                       if (len < 0 && i == size - 2 && c != '\0')
+                               ++i;
                        if (len < 0 && c == '\0')
                                break;
                        switch (c) {
@@ -486,6 +490,9 @@ string_quote(const char *instr, char *outstr, int len, int size)
 
        *s++ = '\"';
        *s = '\0';
+
+       /* Return nonzero if the string was unterminated.  */
+       return i == size;
 }
 
 void
@@ -508,8 +515,7 @@ printpathn(struct tcb *tcp, long addr, int n)
 
                if (trunc)
                        path[n] = '\0';
-               string_quote(path, outstr, -1, n);
-               if (trunc)
+               if (string_quote(path, outstr, -1, n + 1) || trunc)
                        strcat(outstr, "...");
                tprintf("%s", outstr);
        }
@@ -526,7 +532,7 @@ printstr(struct tcb *tcp, long addr, int len)
 {
        static char *str = NULL;
        static char *outstr;
-       int size, trunc;
+       int size;
 
        if (!addr) {
                tprintf("NULL");
@@ -557,9 +563,7 @@ printstr(struct tcb *tcp, long addr, int len)
                }
        }
 
-       trunc = size > max_strlen && str[--size] != 0;
-       string_quote(str, outstr, len, size);
-       if (size < len || (len < 0 && trunc))
+       if (string_quote(str, outstr, len, size))
                strcat(outstr, "...");
 
        tprintf("%s", outstr);