From 857b7a3d6e6295818badb6bccba9c90009639159 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 22 Jan 2018 16:55:51 +0100 Subject: [PATCH] Fix type mismatch calculating new line program offset in debugedit.c. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit edit_dwarf2 calculates the (new) offset in the line program by taking the difference between the old and new idx, which are of type size_t (unsigned), plus the size_diff of the header given as ssize_t (signed), and adding that to the current r_offset, which is an Elf64_Addr (unsigned). On 64bit architectures, where the size of Elf64_Addr and ssize_t are the same this isn't a problem. But on 32bit architectures, where the size of ssize_t is smaller than Elf64_Addr the smaller signed result gets promoted to an unsigned long first causing issues if the size_diff was negative. This would have been caught by gcc -Wsign-conversion warning: conversion to ‘long unsigned int’ from ‘ssize_t’ {aka ‘long int’} may change the sign of the result But enabling this by default gives a lot of false positives. Found and fixed by Richard Biener . --- tools/debugedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/debugedit.c b/tools/debugedit.c index fa47aa5..e0b1d98 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -2154,9 +2154,9 @@ edit_dwarf2 (DSO *dso) /* Offset (pointing into the line program) moves from old to new index including the header size diff. */ - r_offset += ((dso->lines.table[lndx].new_idx - - dso->lines.table[lndx].old_idx) - + dso->lines.table[lndx].size_diff); + r_offset += (ssize_t)((dso->lines.table[lndx].new_idx + - dso->lines.table[lndx].old_idx) + + dso->lines.table[lndx].size_diff); if (rtype == SHT_RELA) {