diff options
author | Simon Glass <sjg@chromium.org> | 2020-11-01 14:15:40 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-12-01 10:33:38 -0500 |
commit | d422c77ae8e0cb1211b34eb4af442600b0da8d5b (patch) | |
tree | 461c03c29dce244867eb635eced3050880eec946 /cmd/setexpr.c | |
parent | 56331b2680d9fef7e60a88fa50d3e167f236c4a0 (diff) | |
download | u-boot-d422c77ae8e0cb1211b34eb4af442600b0da8d5b.tar.gz u-boot-d422c77ae8e0cb1211b34eb4af442600b0da8d5b.tar.bz2 u-boot-d422c77ae8e0cb1211b34eb4af442600b0da8d5b.zip |
setexpr: Add some tests for buffer overflow and backref
Add tests to check for buffer overflow using simple replacement as well
as back references. At present these don't fully pass.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd/setexpr.c')
-rw-r--r-- | cmd/setexpr.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/cmd/setexpr.c b/cmd/setexpr.c index fe3435b4d9..dbb43b3be2 100644 --- a/cmd/setexpr.c +++ b/cmd/setexpr.c @@ -134,22 +134,8 @@ static char *substitute(char *string, int *slen, int ssize, return p + nlen; } -/** - * regex_sub() - Replace a regex pattern with a string - * - * @data: Buffer containing the string to update - * @data_size: Size of buffer (must be large enough for the new string) - * @nbuf: Back-reference buffer - * @nbuf_size: Size of back-reference buffer (must be larger enough for @s plus - * all back-reference expansions) - * @r: Regular expression to find - * @s: String to replace with - * @global: true to replace all matches in @data, false to replace just the - * first - * @return 0 if OK, 1 on error - */ -static int regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, - const char *r, const char *s, bool global) +int setexpr_regex_sub(char *data, uint data_size, char *nbuf, uint nbuf_size, + const char *r, const char *s, bool global) { struct slre slre; char *datap = data; @@ -325,7 +311,8 @@ static int regex_sub_var(const char *name, const char *r, const char *s, strcpy(data, t); - ret = regex_sub(data, SLRE_BUFSZ, nbuf, SLRE_PATSZ, r, s, global); + ret = setexpr_regex_sub(data, SLRE_BUFSZ, nbuf, SLRE_PATSZ, r, s, + global); if (ret) return 1; |