summaryrefslogtreecommitdiff
path: root/backport-CVE-2022-48174.patch
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-10-24 06:18:01 +0000
committerCoprDistGit <infra@openeuler.org>2023-10-24 06:18:01 +0000
commit4de5a63ac5c24b1e0c7ef8ad2a5ef894b4171cc7 (patch)
treeac26f83c576353146dd6bc391b5b899268722e8d /backport-CVE-2022-48174.patch
parent0304f2dd6d580c9313752d84257291c8ad57e47f (diff)
automatic import of busyboxopeneuler23.09openeuler22.03_LTS
Diffstat (limited to 'backport-CVE-2022-48174.patch')
-rw-r--r--backport-CVE-2022-48174.patch77
1 files changed, 77 insertions, 0 deletions
diff --git a/backport-CVE-2022-48174.patch b/backport-CVE-2022-48174.patch
new file mode 100644
index 0000000..0ab1624
--- /dev/null
+++ b/backport-CVE-2022-48174.patch
@@ -0,0 +1,77 @@
+From 1c4fc3ab4f6241a05a24b0593ce63bcb54e469eb Mon Sep 17 00:00:00 2001
+From: songbuhuang <544824346@qq.com>
+Date: Thu, 31 Aug 2023 11:39:36 +0800
+Subject: [PATCH] fix CVE-2022-48174
+
+Signed-off-by: songbuhuang <544824346@qq.com>
+---
+ shell/math.c | 39 +++++++++++++++++++++++++++++++++++----
+ 1 file changed, 35 insertions(+), 4 deletions(-)
+
+diff --git a/shell/math.c b/shell/math.c
+index 76d22c9..727c294 100644
+--- a/shell/math.c
++++ b/shell/math.c
+@@ -577,6 +577,28 @@ static arith_t strto_arith_t(const char *nptr, char **endptr)
+ # endif
+ #endif
+
++//TODO: much better estimation than expr_len/2? Such as:
++//static unsigned estimate_nums_and_names(const char *expr)
++//{
++// unsigned count = 0;
++// while (*(expr = skip_whitespace(expr)) != '\0') {
++// const char *p;
++// if (isdigit(*expr)) {
++// while (isdigit(*++expr))
++// continue;
++// count++;
++// continue;
++// }
++// p = endofname(expr);
++// if (p != expr) {
++// expr = p;
++// count++;
++// continue;
++// }
++// }
++// return count;
++//}
++
+ static arith_t
+ evaluate_string(arith_state_t *math_state, const char *expr)
+ {
+@@ -584,10 +606,12 @@ evaluate_string(arith_state_t *math_state, const char *expr)
+ const char *errmsg;
+ const char *start_expr = expr = skip_whitespace(expr);
+ unsigned expr_len = strlen(expr) + 2;
+- /* Stack of integers */
+- /* The proof that there can be no more than strlen(startbuf)/2+1
+- * integers in any given correct or incorrect expression
+- * is left as an exercise to the reader. */
++ /* Stack of integers/names */
++ /* There can be no more than strlen(startbuf)/2+1
++ * integers/names in any given correct or incorrect expression.
++ * (modulo "09v09v09v09v09v" case,
++ * but we have code to detect that early)
++ */
+ var_or_num_t *const numstack = alloca((expr_len / 2) * sizeof(numstack[0]));
+ var_or_num_t *numstackptr = numstack;
+ /* Stack of operator tokens */
+@@ -652,6 +676,13 @@ evaluate_string(arith_state_t *math_state, const char *expr)
+ numstackptr->var = NULL;
+ errno = 0;
+ numstackptr->val = strto_arith_t(expr, (char**) &expr);
++ /* A number can't be followed by another number, or a variable name.
++ * We'd catch this later anyway, but this would require numstack[]
++ * to be twice as deep to handle strings where _every_ char is
++ * a new number or name. Example: 09v09v09v09v09v09v09v09v09v
++ */
++ if (isalnum(*expr) || *expr == '_')
++ goto err;
+ //bb_error_msg("val:%lld", numstackptr->val);
+ if (errno)
+ numstackptr->val = 0; /* bash compat */
+--
+2.26.2
+