• Arnaldo Carvalho de Melo's avatar
    perf svghelper: Fix unchecked usage of strncpy() · 5d9435e2
    Arnaldo Carvalho de Melo authored
    [ Upstream commit 2f530253 ]
    
    The strncpy() function may leave the destination string buffer
    unterminated, better use strlcpy() that we have a __weak fallback
    implementation for systems without it.
    
    In this specific case this would only happen if fgets() was buggy, as
    its man page states that it should read one less byte than the size of
    the destination buffer, so that it can put the nul byte at the end of
    it, so it would never copy 255 non-nul chars, as fgets reads into the
    orig buffer at most 254 non-nul chars and terminates it. But lets just
    switch to strlcpy to keep the original intent and silence the gcc 8.2
    warning.
    
    This fixes this warning on an Alpine Linux Edge system with gcc 8.2:
    
      In function 'cpu_model',
          inlined from 'svg_cpu_box' at util/svghelper.c:378:2:
      util/svghelper.c:337:5: error: 'strncpy' output may be truncated copying 255 bytes from a string of length 255 [-Werror=stringop-truncation]
           strncpy(cpu_m, &buf[13], 255);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Arjan van de Ven <arjan@linux.intel.com>
    Fixes: f48d55ce ("perf: Add a SVG helper library file")
    Link: https://lkml.kernel.org/n/tip-xzkoo0gyr56gej39ltivuh9g@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    5d9435e2
Name
Last commit
Last update
..
Documentation Loading commit data...
arch Loading commit data...
bench Loading commit data...
examples/bpf Loading commit data...
include/bpf Loading commit data...
jvmti Loading commit data...
pmu-events Loading commit data...
python Loading commit data...
scripts Loading commit data...
tests Loading commit data...
trace Loading commit data...
ui Loading commit data...
util Loading commit data...
.gitignore Loading commit data...
Build Loading commit data...
CREDITS Loading commit data...
MANIFEST Loading commit data...
Makefile Loading commit data...
Makefile.config Loading commit data...
Makefile.perf Loading commit data...
builtin-annotate.c Loading commit data...
builtin-bench.c Loading commit data...
builtin-buildid-cache.c Loading commit data...
builtin-buildid-list.c Loading commit data...
builtin-c2c.c Loading commit data...
builtin-config.c Loading commit data...
builtin-data.c Loading commit data...
builtin-diff.c Loading commit data...
builtin-evlist.c Loading commit data...
builtin-ftrace.c Loading commit data...
builtin-help.c Loading commit data...
builtin-inject.c Loading commit data...
builtin-kallsyms.c Loading commit data...
builtin-kmem.c Loading commit data...
builtin-kvm.c Loading commit data...
builtin-list.c Loading commit data...
builtin-lock.c Loading commit data...
builtin-mem.c Loading commit data...
builtin-probe.c Loading commit data...
builtin-record.c Loading commit data...
builtin-report.c Loading commit data...
builtin-sched.c Loading commit data...
builtin-script.c Loading commit data...
builtin-stat.c Loading commit data...
builtin-timechart.c Loading commit data...
builtin-top.c Loading commit data...
builtin-trace.c Loading commit data...
builtin-version.c Loading commit data...
builtin.h Loading commit data...
check-headers.sh Loading commit data...
command-list.txt Loading commit data...
design.txt Loading commit data...
perf-archive.sh Loading commit data...
perf-completion.sh Loading commit data...
perf-read-vdso.c Loading commit data...
perf-sys.h Loading commit data...
perf-with-kcore.sh Loading commit data...
perf.c Loading commit data...
perf.h Loading commit data...