diff options
author | Martin Willi <martin@revosec.ch> | 2014-01-15 18:18:24 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-01-15 18:28:43 +0100 |
commit | 2e89bc4b66fcfac358443201fc0b99b64ddb432f (patch) | |
tree | c125128a1c0fcb9ea2d225b05cdfe6a5e73d1977 /src/libstrongswan/utils/printf_hook/printf_hook_builtin.c | |
parent | a48d19a3bfa999b0aa5451ebb258f5411c027173 (diff) | |
download | strongswan-2e89bc4b66fcfac358443201fc0b99b64ddb432f.tar.bz2 strongswan-2e89bc4b66fcfac358443201fc0b99b64ddb432f.tar.xz |
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.
Diffstat (limited to 'src/libstrongswan/utils/printf_hook/printf_hook_builtin.c')
-rw-r--r-- | src/libstrongswan/utils/printf_hook/printf_hook_builtin.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c b/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c index 7ed3979a0..c79d4b87a 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; } |