Skip to content

Commit fc47611

Browse files
pmladekKernel Patches Daemon
authored andcommitted
kallsyms: Clean up @namebuf initialization in kallsyms_lookup_buildid()
The function kallsyms_lookup_buildid() initializes the given @namebuf by clearing the first and the last byte. It is not clear why. The 1st byte makes sense because some callers ignore the return code and expect that the buffer contains a valid string, for example: - function_stat_show() - kallsyms_lookup() - kallsyms_lookup_buildid() The initialization of the last byte does not make much sense because it can later be overwritten. Fortunately, it seems that all called functions behave correctly: - kallsyms_expand_symbol() explicitly adds the trailing '\0' at the end of the function. - All *__address_lookup() functions either use the safe strscpy() or they do not touch the buffer at all. Document the reason for clearing the first byte. And remove the useless initialization of the last byte. Signed-off-by: Petr Mladek <[email protected]>
1 parent baa9ce7 commit fc47611

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kernel/kallsyms.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,12 @@ static int kallsyms_lookup_buildid(unsigned long addr,
352352
{
353353
int ret;
354354

355-
namebuf[KSYM_NAME_LEN - 1] = 0;
355+
/*
356+
* kallsyms_lookus() returns pointer to namebuf on success and
357+
* NULL on error. But some callers ignore the return value.
358+
* Instead they expect @namebuf filled either with valid
359+
* or empty string.
360+
*/
356361
namebuf[0] = 0;
357362

358363
if (is_ksym_addr(addr)) {

0 commit comments

Comments
 (0)