diff options
author | Martin Lewis <martin.lewis.x84@gmail.com> | 2020-06-11 15:45:58 -0500 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-06-29 16:09:46 +0200 |
commit | c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8 (patch) | |
tree | 865dd68e4c300a6eec1d250282bc1874f7bcbb27 | |
parent | ac79db6a3b8c9d1815dc4f506d55bc6a2a4e34dd (diff) | |
download | busybox-w32-c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8.tar.gz busybox-w32-c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8.tar.bz2 busybox-w32-c9fc15359ef8fe5aa98ab0308c1563d9bcf99bb8.zip |
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>
-rw-r--r-- | libbb/compare_string_array.c | 7 |
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) | |||
117 | const char* FAST_FUNC nth_string(const char *strings, int n) | 117 | const char* FAST_FUNC nth_string(const char *strings, int n) |
118 | { | 118 | { |
119 | while (n) { | 119 | while (n) { |
120 | n--; | 120 | if (*strings++ == '\0') { |
121 | strings += strlen(strings) + 1; | 121 | if (*strings == '\0') /* reached end of strings */ |
122 | break; | ||
123 | n--; | ||
124 | } | ||
122 | } | 125 | } |
123 | return strings; | 126 | return strings; |
124 | } | 127 | } |