dsp-kernel: use memcpy() instead of strcpy()
Current code uses strcpy() to copy strings, which has a problem with potential buffer overflows if the source string is longer than the destination buffer. We can improve this by using memcpy() with a specified length, because it allows us to control the number of bytes copied and thus prevent buffer overflows. Change-Id: I9dd5da343bfd63e4e031a66fa26b103e3da573e0 Signed-off-by: mingzh <quic_mingzh@quicinc.com>
This commit is contained in:
@@ -385,7 +385,10 @@ TRACE_EVENT(fastrpc_msg,
|
|||||||
memcpy(__get_str(buf), (message), (sizeof(message) - 1));
|
memcpy(__get_str(buf), (message), (sizeof(message) - 1));
|
||||||
__get_str(buf)[sizeof(message) - 1] = '\0';
|
__get_str(buf)[sizeof(message) - 1] = '\0';
|
||||||
#else
|
#else
|
||||||
__assign_str(buf, message);
|
if (message)
|
||||||
|
__assign_str_len(buf, message, (sizeof(message) - 1));
|
||||||
|
else
|
||||||
|
memcpy(__get_str(buf), "(null)", sizeof("(null)"));
|
||||||
#endif
|
#endif
|
||||||
),
|
),
|
||||||
TP_printk(" %s", __get_str(buf))
|
TP_printk(" %s", __get_str(buf))
|
||||||
@@ -410,7 +413,10 @@ TRACE_EVENT(fastrpc_dspsignal,
|
|||||||
memcpy(__get_str(buf), (event), (sizeof(event) - 1));
|
memcpy(__get_str(buf), (event), (sizeof(event) - 1));
|
||||||
__get_str(buf)[sizeof(event) - 1] = '\0';
|
__get_str(buf)[sizeof(event) - 1] = '\0';
|
||||||
#else
|
#else
|
||||||
__assign_str(buf, event);
|
if (event)
|
||||||
|
__assign_str_len(buf, event, (sizeof(event) - 1));
|
||||||
|
else
|
||||||
|
memcpy(__get_str(buf), "(null)", sizeof("(null)"));
|
||||||
#endif
|
#endif
|
||||||
__entry->signal_id = signal_id;
|
__entry->signal_id = signal_id;
|
||||||
__entry->state = state;
|
__entry->state = state;
|
||||||
|
|||||||
Reference in New Issue
Block a user