Skip to content

Commit 81fccd6

Browse files
Thomas Richteracmel
authored andcommitted
perf record: Fix failed memory allocation for get_cpuid_str
In x86 architecture dependend part function get_cpuid_str() mallocs a 128 byte buffer, but does not check if the memory allocation succeeded or not. When the memory allocation fails, function __get_cpuid() is called with first parameter being a NULL pointer. However this function references its first parameter and operates on a NULL pointer which might cause core dumps. Signed-off-by: Thomas Richter <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Hendrik Brueckner <[email protected]> Cc: Martin Schwidefsky <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent cc2ef58 commit 81fccd6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/arch/x86/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
7070
{
7171
char *buf = malloc(128);
7272

73-
if (__get_cpuid(buf, 128, "%s-%u-%X$") < 0) {
73+
if (buf && __get_cpuid(buf, 128, "%s-%u-%X$") < 0) {
7474
free(buf);
7575
return NULL;
7676
}

0 commit comments

Comments
 (0)