mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 10:39:08 +00:00
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: 855f18ea0e
("setexpr: add regex substring matching and substitution")
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d422c77ae8
commit
9528229f22
2 changed files with 3 additions and 8 deletions
|
@ -147,11 +147,6 @@ int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size,
|
|||
}
|
||||
|
||||
len = strlen(data);
|
||||
if (s == NULL)
|
||||
nlen = 0;
|
||||
else
|
||||
nlen = strlen(s);
|
||||
|
||||
for (loop = 0;; loop++) {
|
||||
struct cap caps[slre.num_caps + 2];
|
||||
const char *old;
|
||||
|
@ -187,6 +182,7 @@ int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size,
|
|||
|
||||
old = caps[0].ptr;
|
||||
olen = caps[0].len;
|
||||
nlen = strlen(s);
|
||||
|
||||
if (nlen + 1 >= nbuf_size) {
|
||||
printf("## error: pattern buffer overflow: have %d, need %d\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue