aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorMartin Lewis <martin.lewis.x84@gmail.com>2020-06-11 15:45:58 -0500
committerDenys Vlasenko <vda.linux@googlemail.com>2020-06-29 16:09:46 +0200
commitc9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8 (patch)
tree865dd68e4c300a6eec1d250282bc1874f7bcbb27 /libbb
parentac79db6a3b8c9d1815dc4f506d55bc6a2a4e34dd (diff)
downloadbusybox-c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8.tar.gz
compare_string_array: code shrink
Code shrink and prevention of possible out of bounds access. function old new delta nth_string 36 26 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-10) Total: -10 bytes text data bss dec hex filename 981342 16915 1872 1000129 f42c1 busybox_old 981332 16915 1872 1000119 f42b7 busybox_unstripped Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/compare_string_array.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 01a9df0e2..a06e57d3d 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -117,8 +117,11 @@ int FAST_FUNC index_in_substrings(const char *strings, const char *key)
const char* FAST_FUNC nth_string(const char *strings, int n)
{
while (n) {
- n--;
- strings += strlen(strings) + 1;
+ if (*strings++ == '\0') {
+ if (*strings == '\0') /* reached end of strings */
+ break;
+ n--;
+ }
}
return strings;
}