summaryrefslogtreecommitdiffhomepage
path: root/ir/libcore
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-10-02 10:28:50 +0200
committerMatthias Braun <matze@braunis.de>2015-10-02 10:29:40 +0200
commitef5f90e4998956641fab41462021e36a39a19d5b (patch)
tree6da3aeeb1dafbb418c5545af9e217e0b4c4672cf /ir/libcore
parent2f546a03d8fc20405630d8a25af5792007fbc10d (diff)
libcore: Fix out of bounds read
... by rewriting stupid code.
Diffstat (limited to 'ir/libcore')
-rw-r--r--ir/libcore/lc_opts.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/ir/libcore/lc_opts.c b/ir/libcore/lc_opts.c
index edb43f0..6c2893c 100644
--- a/ir/libcore/lc_opts.c
+++ b/ir/libcore/lc_opts.c
@@ -246,11 +246,13 @@ lc_opt_entry_t *lc_opt_resolve_opt(const lc_opt_entry_t *root,
return lc_opt_find_opt(grp, names[n - 1]);
}
-static char *strtolower(char *buf, size_t n, const char *str)
+static bool streq_lower(const char *s0, const char *s1)
{
- for (unsigned i = 0; i < n; ++i)
- buf[i] = tolower((unsigned char)str[i]);
- return buf;
+ for ( ; *s0 != '\0' && *s1 != '\0'; ++s0, ++s1) {
+ if (tolower((unsigned char)*s0) != tolower((unsigned char)*s1))
+ return false;
+ }
+ return *s0 == *s1;
}
static bool string_to_bool(bool *const val, char const *const value)
@@ -269,10 +271,8 @@ static bool string_to_bool(bool *const val, char const *const value)
{ "0", 0 },
};
- char buf[16];
- strtolower(buf, sizeof(buf), value);
for (unsigned i = 0; i < ARRAY_SIZE(bool_strings); ++i) {
- if (strcmp(buf, bool_strings[i].str) == 0) {
+ if (streq_lower(value, bool_strings[i].str)) {
*val = bool_strings[i].val;
return true;
}