Skip to content

Commit 92ef216

Browse files
committed
pp_multiconcat: don't set svpv_p to an invalid pointer
When svpv_base == svpv_buf, svpv_p would be set to point before the buffer, which is undefined. This appears to be what gcc 13 is complaining about in #20678, despite that report including what appears to be a completely valid address, on a line where the value of svpv_p is now within the range of svpv_buf. An intermediate approach to this used: temp = svpv_p; if (svpv_p++ == svpv_end) break but this is also incorrect, since svpv_p would end up as an invalid pointer, though gcc UBSAN didn't pick that up. Fixes #20678.
1 parent 2ef2082 commit 92ef216

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pp_hot.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ PP(pp_multiconcat)
957957
/* Note that we iterate the loop nargs+1 times: to append nargs
958958
* arguments and nargs+1 constant strings. For example, "-$a-$b-"
959959
*/
960-
svpv_p = svpv_base - 1;
960+
svpv_p = svpv_base;
961961

962962
for (;;) {
963963
SSize_t len = (const_lens++)->ssize;
@@ -969,7 +969,7 @@ PP(pp_multiconcat)
969969
const_pv += len;
970970
}
971971

972-
if (++svpv_p == svpv_end)
972+
if (svpv_p == svpv_end)
973973
break;
974974

975975
/* append next arg */
@@ -997,6 +997,7 @@ PP(pp_multiconcat)
997997
targ_pv += len;
998998
}
999999

1000+
++svpv_p;
10001001
}
10011002
}
10021003

0 commit comments

Comments
 (0)