Commit f0d98c78 authored by Suchit Karunakaran's avatar Suchit Karunakaran Committed by Arnaldo Carvalho de Melo
Browse files

perf annotate: Fix memcpy size in arch__grow_instructions()



The memcpy() in arch__grow_instructions() is copying the wrong number of
bytes when growing from a non-allocated table.

It should copy arch->nr_instructions * sizeof(struct ins) bytes, not
just arch->nr_instructions bytes.

This bug causes data corruption as only a partial copy of the
instruction table is made, leading to garbage data in most entries and
potential crashes

Fixes: 2a1ff812 ("perf annotate: Introduce alternative method of keeping instructions table")
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarSuchit Karunakaran <suchitkarunakaran@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c5e47e4d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ static int arch__grow_instructions(struct arch *arch)
	if (new_instructions == NULL)
		return -1;

	memcpy(new_instructions, arch->instructions, arch->nr_instructions);
	memcpy(new_instructions, arch->instructions, arch->nr_instructions * sizeof(struct ins));
	goto out_update_instructions;
}