draios/sysdig — pull request #248 by acarpi (2014-09-23 07:19:21+00:00)
Title: Make sure there is enough buffer space in binary_buffer_to_base64_string()

Hi everyone,

just noticed the -b/--print-base64 format was buggy with large event buffer, causing sysdig to crash printing a backtrace. I isolated a capture able to reproduce the bug consistently at every run.

A quick valgrind run isolated the issue as belonging to my new function binary_buffer_to_base64_string():
==2306== ERROR SUMMARY: 64 errors from 4 contexts (suppressed: 2 from 2)
==2306==
==2306== 16 errors in context 1 of 4:
==2306== Invalid write of size 1
==2306== at 0x4370A8: binary_buffer_to_base64_string(char*, char*, unsigned int, unsigned int, sinsp_evt::param_fmt) (event.cpp:456)

This simple fix will make sure I account for the buffer size similarly to other print format functions: the test is now passing and valgrind doesn't complain anymore.