• Arnaldo Carvalho de Melo's avatar
    perf header: Fix unchecked usage of strncpy() · 5192bde7
    Arnaldo Carvalho de Melo authored
    The strncpy() function may leave the destination string buffer
    unterminated, better use strlcpy() that we have a __weak fallback
    implementation for systems without it.
    
    This fixes this warning on an Alpine Linux Edge system with gcc 8.2:
    
      util/header.c: In function 'perf_event__synthesize_event_update_name':
      util/header.c:3625:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
        strncpy(ev->data, evsel->name, len);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      util/header.c:3618:15: note: length computed here
        size_t len = strlen(evsel->name);
                     ^~~~~~~~~~~~~~~~~~~
    
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Fixes: a6e52817 ("perf tools: Add event_update event unit type")
    Link: https://lkml.kernel.org/n/tip-wycz66iy8dl2z3yifgqf894p@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    5192bde7
header.c 84.3 KB