]> granicus.if.org Git - strace/commitdiff
printstr_ex: fix handling of last byte when QUOTE_0_TERMINATED bit set
authorDmitry V. Levin <ldv@altlinux.org>
Sun, 20 Nov 2016 00:29:46 +0000 (00:29 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 20 Nov 2016 00:29:46 +0000 (00:29 +0000)
* util.c (printstr_ex): Simplify handling of size == 0 case.
Do not artificially decrement size when QUOTE_0_TERMINATED bit is set.
Ensure that str[size] byte is non-zero if it hasn't been fetched.

util.c

diff --git a/util.c b/util.c
index 0279705acdd978299b7f0aae18102cbc799220ce..e83f574aab28520654f5d9ed3866722b81bf6e6f 100644 (file)
--- a/util.c
+++ b/util.c
@@ -879,23 +879,18 @@ printstr_ex(struct tcb *tcp, long addr, long len, unsigned int user_style)
                return;
        }
 
-       if (style & QUOTE_0_TERMINATED) {
-               if (size) {
-                       --size;
-               } else {
-                       tprints((len == -1) || (len == 0) ? "\"\"" : "\"\"...");
-                       return;
-               }
-       }
        if (size > max_strlen)
                size = max_strlen;
+       else
+               str[size] = '\xff';
 
        /* If string_quote didn't see NUL and (it was supposed to be ASCIZ str
         * or we were requested to print more than -s NUM chars)...
         */
-       ellipsis = (string_quote(str, outstr, size, style) &&
-                       ((style & QUOTE_0_TERMINATED) ||
-                               (unsigned long) len > max_strlen));
+       ellipsis = string_quote(str, outstr, size, style)
+                  && len
+                  && ((style & QUOTE_0_TERMINATED)
+                      || (unsigned long) len > max_strlen);
 
        tprints(outstr);
        if (ellipsis)