From 71da7f64e27e8b915e3544a8f0bb2ec384878c0e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 4 Jan 2023 08:38:23 -0600 Subject: [PATCH] Fix next ASAN issue in toysh. If strchr("haystack", needle) gets 0 for needle, it matches the NUL at the end of the string: stridx() intentionally does NOT do that. --- toys/pending/sh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 107ef0f7..d9abb61a 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -636,7 +636,7 @@ static int recalculate(long long *dd, char **ss, int lvl) *ss += 2; // Assignment operators: = *= /= %= += -= <<= >>= &= ^= |= - } else if (lvl<=2 && (*ss)[ii = !!strchr("*/%+-", **ss) + } else if (lvl<=2 && (*ss)[ii = (-1 != stridx("*/%+-", **ss)) +2*!xmemcmp(*ss, "<<", 2)+2*!xmemcmp(*ss, ">>", 2)]=='=') { // TODO: assignments are lower priority BUT must go after variable, -- 2.39.2