From: Martin Willi Date: Wed, 15 Jan 2014 17:18:24 +0000 (+0100) Subject: printf-hook-builtin: Correctly calculate written bytes in print_in_hook() X-Git-Tag: 5.1.2rc1~72 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e89bc4b66fcfac358443201fc0b99b64ddb432f;p=thirdparty%2Fstrongswan.git printf-hook-builtin: Correctly calculate written bytes in print_in_hook() The hook data counts remaining buffer bytes, not used ones. Counting them correctly fixes a crash for long hexdumps. Further, print_in_hook() must return the number of bytes that would have been written, not the actually written bytes. This is important, as we allocate a dynamic buffer in bus that relies on the exact byte count. Fixes long hexdumps that got truncated. --- diff --git a/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c b/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c index 7ed3979a0b..c79d4b87a6 100644 --- a/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c +++ b/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c @@ -122,10 +122,14 @@ size_t print_in_hook(printf_hook_data_t *data, char *fmt, ...) if (written > data->n) { - written = data->n; + data->q += data->n; + data->n = 0; + } + else + { + data->q += written; + data->n -= written; } - data->q += written; - data->n += written; return written; }