[lttng-dev] How to ensure null char to string field?
francis.giraldeau at gmail.com
Mon May 28 06:53:28 EDT 2012
I want to save a string from user space through a proc file. It seems
trivial, but I have a problem with null termination. The user space
string is _not_ null terminated. Here is an hexdump of the string bytes
for "bidon" after performing copy_from_user on the kernel stack:
[ 3163.957414] 0x62 0x69 0x64 0x6F 0x6E 0xFFFFFFDF ...
The tracepoint I use is:
TP_PROTO(const char * str),
The user_strlen continues beyond the real string length because it's not
null terminated. The string length is already known (given as a
parameter of the write callback), such that I would like to copy only
this number of bytes and then set last byte to '\0'. Also, this would be
required to limit the string size.
I have not found a way to do it with current macros. Shall a new macro
to handle this use case be added?
More information about the lttng-dev