[binutils-gdb] gas: avoid UB on signed multiplication in resolve_symbol_value()

Jan Beulich jbeulich@sourceware.org
Fri Dec 13 08:43:45 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bbe22ca078c02ca248722832fd77e2a6cd2813c5

commit bbe22ca078c02ca248722832fd77e2a6cd2813c5
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Dec 13 09:42:55 2024 +0100

    gas: avoid UB on signed multiplication in resolve_symbol_value()
    
    Commit 487b0ff02dda ("ubsan: signed integer multiply overflow") touched
    only one of the two affected places (the 3rd, resolve_expression(), is
    already using valueT type local variables).

Diff:
---
 gas/symbols.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gas/symbols.c b/gas/symbols.c
index fa3aaa37ed4..8401b4e425e 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -1721,7 +1721,8 @@ resolve_symbol_value (symbolS *symp)
 
 	  switch (symp->x->value.X_op)
 	    {
-	    case O_multiply:		left *= right; break;
+	    /* See expr() for reasons of the use of valueT casts here.  */
+	    case O_multiply:		left *= (valueT) right; break;
 	    case O_divide:		left /= right; break;
 	    case O_modulus:		left %= right; break;
 	    case O_left_shift:


More information about the Binutils-cvs mailing list