[hackers] [sbase] printf: handle \0 in %b arguments || Evan Gates

From: <git_AT_suckless.org>
Date: Tue, 27 Dec 2016 15:04:02 +0100 (CET)

commit 123f784ccc9138ce09176cdc2d3eae23af454941
Author: Evan Gates <evan.gates_AT_gmail.com>
AuthorDate: Mon Oct 24 08:16:25 2016 -0700
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Dec 27 13:25:38 2016 +0100

    printf: handle \0 in %b arguments
    
    The %b case was using fputs after unescape to print the argument, which
    meant that it could not handle nul bytes. Instead, store the length
    returned from unescape and use fwrite to properly handle them.

diff --git a/printf.c b/printf.c
index 7bf6fe5..4bc645b 100644
--- a/printf.c
+++ b/printf.c
_AT_@ -19,7 +19,7 @@ int
 main(int argc, char *argv[])
 {
         Rune *rarg;
- size_t i, j, argi, lastargi, formatlen;
+ size_t i, j, argi, lastargi, formatlen, blen;
         long long num;
         double dou;
         int cooldown = 0, width, precision, ret = 0;
_AT_@ -112,12 +112,12 @@ main(int argc, char *argv[])
                 case 'b':
                         if ((tmp = strstr(arg, "\\c"))) {
                                 *tmp = 0;
- unescape(arg);
- fputs(arg, stdout);
+ blen = unescape(arg);
+ fwrite(arg, sizeof(*arg), blen, stdout);
                                 return 0;
                         }
- unescape(arg);
- fputs(arg, stdout);
+ blen = unescape(arg);
+ fwrite(arg, sizeof(*arg), blen, stdout);
                         break;
                 case 'c':
                         unescape(arg);
Received on Tue Dec 27 2016 - 15:04:02 CET

This archive was generated by hypermail 2.3.0 : Tue Dec 27 2016 - 15:13:14 CET