[lttng-dev] How to ensure null char to string field?
Francis Giraldeau
francis.giraldeau at gmail.com
Mon May 28 06:53:28 EDT 2012
Hi,
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:
TRACE_EVENT(lttng_uevent_cfu,
TP_PROTO(const char * str),
TP_ARGS(str),
TP_STRUCT__entry(__string_from_user(str, str)),
TP_fast_assign(tp_copy_string_from_user(str, str)),
TP_printk()
)
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?
Cheers,
Francis Giraldeau
More information about the lttng-dev
mailing list