]> git.dujemihanovic.xyz Git - u-boot.git/commit
setexpr: Correct dropping of final unmatched string
authorSimon Glass <sjg@chromium.org>
Sun, 1 Nov 2020 21:15:41 +0000 (14:15 -0700)
committerTom Rini <trini@konsulko.com>
Tue, 1 Dec 2020 15:33:38 +0000 (10:33 -0500)
commit9528229f22b590cc4b5cf8bf0d3212d2ab08ffd5
tree8ee940415eb9a1c3148acdc510d82ae7abd1c68f
parentd422c77ae8e0cb1211b34eb4af442600b0da8d5b
setexpr: Correct dropping of final unmatched string

At present the 'nlen' variable increases with each loop. If the previous
loop had back references, then subsequent loops without back references
use the wrong value of nlen. The value is larger, meaning that the string
terminator from nbuf is copied along to the main buffer, thus terminating
the string prematurely.

This leads to the final result being truncated, e.g. missing the last
(unmatched) part of the string. So "match match tail" become
"replaced replaced" instead of "replaced replaced tail".

Fix this by resetting nlen to the correct value each time around the lop.

Fixes: 855f18ea0e6 ("setexpr: add regex substring matching and substitution")
Signed-off-by: Simon Glass <sjg@chromium.org>
cmd/setexpr.c
test/cmd/setexpr.c