tools/perf: use local variable for segment file offset
PATCH 1/1 tools/perf: use local variable for segment file offset
The value of phdr->p_offset is stored inside a buffer that gets reallocated, so it could become corrupted if the new size isn't big enough to contain it
Signed-off-by Romeo Cane <[email protected]>
--- tools/perf/util/symbol-minimal.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/util/symbol-minimal.c +6 -2
@@ -129,6 +129,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)for (i =0 , phdr = buf; i < ehdr.e_phnum; i++, phdr++) {void *tmp; +Elf32_Off tmp_off;if (need_swap) { phdr->p_type =bswap_32 (phdr->p_type);
@@ -140,12 +141,13 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)continue ; buf_size = phdr->p_filesz; + tmp_off = phdr->p_offset; tmp =realloc (buf, buf_size);if (tmp ==NULL ) goto out_free; buf = tmp; -fseek (fp, phdr->p_offset,SEEK_SET ); +fseek (fp, tmp_off,SEEK_SET );if (fread (buf, buf_size,1 , fp) !=1 ) goto out_free;
@@ -178,6 +180,7 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)for (i =0 , phdr = buf; i < ehdr.e_phnum; i++, phdr++) {void *tmp; +Elf64_Off tmp_off;if (need_swap) { phdr->p_type =bswap_32 (phdr->p_type);
@@ -189,12 +192,13 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)continue ; buf_size = phdr->p_filesz; + tmp_off = phdr->p_offset; tmp =realloc (buf, buf_size);if (tmp ==NULL ) goto out_free; buf = tmp; -fseek (fp, phdr->p_offset,SEEK_SET ); +fseek (fp, tmp_off,SEEK_SET );if (fread (buf, buf_size,1 , fp) !=1 ) goto out_free;
Signature · 1 line
1.8.3.2