ref-filter.c: don't stomp on memory
PATCH 1/1 ref-filter.c: don't stomp on memory
---
Hi Karthik,
If you need to re-roll your 'kn/ref-filter-atom-parsing' branch, could you please squash this (or something like it) into the relevant patch (commit 6613d5f1, "ref-filter: introduce parsing functions for each valid atom", 31-01-2016).
This evening, (by mistake!) I built the pu branch with -fsanitize=address in my CFLAGS. This resulted in many test failures, which were all caused by the memcmp() call below stomping all over memory.
Hmm, as I was writing this email, I had a vague recollection of another email on the list recently mentioning this code. So, if this has already been reported, sorry for the noise!
ATB,
Ramsay Jones
ref-filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ref-filter.c +2 -1
@@ -260,7 +260,8 @@ int parse_ref_filter_atom(const char *atom, const char *ep)* table. */ arg =memchr (sp,':' , ep - sp); -if ((!arg || len == arg - sp) && +if ((( arg && len == arg - sp) || + (!arg && len == ep - sp )) && !memcmp (valid_atom[i].name, sp, len))break ; }
Signature · 1 line
2.7.0
Quoted 5 lines · Ramsay Jones
If you need to re-roll your 'kn/ref-filter-atom-parsing' branch, could you please squash this (or something like it) into the relevant patch (commit
6613d5f1, "ref-filter: introduce parsing functions for each valid atom", 31-01-2016).
Quoted 7 lines
This evening, (by mistake!) I built the pu branch with -fsanitize=address in my CFLAGS. This resulted in many test failures, which were all caused by the
memcmp()call below stomping all over memory.Hmm, as I was writing this email, I had a vague recollection of another email on the list recently mentioning this code. So, if this has already been reported, sorry for the noise!
You're probably thinking of [1]. Interestingly, the two proposed fixes differ... (more below)
ref-filter.c int parse_ref_filter_atom(const char *atom, const char *ep) · line 267
Quoted 11 lines
ref-filter.c +2
-1@@ -260,7 +260,8 @@ int parse_ref_filter_atom(const char *atom, const char *ep)* table. */ arg =memchr (sp,':' , ep - sp); -if ((!arg || len == arg - sp) && +if ((( arg && len == arg - sp) || + (!arg && len == ep - sp )) && !memcmp (valid_atom[i].name, sp, len))break ; }
Your fix is pretty easy to to read and seems correct. Karthik's fix required several re-reads, and I *think* it may be correct, however, it's difficult to grok due to its logic inversion.
Aside from the two proposed fixes, a fix patterned after the original code which patch 5/12 replaced would be even easier to understand. That is, something like this:
arg = memchr(...);
if (!arg)
arg = ep;
if (len == arg - sp && !memcmp(...))
...Quoted 7 lines · Eric Sunshine
Quoted 5 lines · Ramsay Jones
If you need to re-roll your 'kn/ref-filter-atom-parsing' branch, could you please squash this (or something like it) into the relevant patch (commit
6613d5f1, "ref-filter: introduce parsing functions for each valid atom", 31-01-2016).
Quoted 8 lines
Quoted 7 lines
This evening, (by mistake!) I built the pu branch with -fsanitize=address in my CFLAGS. This resulted in many test failures, which were all caused by the
memcmp()call below stomping all over memory.Hmm, as I was writing this email, I had a vague recollection of another email on the list recently mentioning this code. So, if this has already been reported, sorry for the noise!
Thanks for reporting, I stumbled upon the same problem myself.
Quoted 5 lines
You're probably thinking of [1]. Interestingly, the two proposed fixes differ... (more below)
Quoted 16 lines
ref-filter.c int parse_ref_filter_atom(const char *atom, const char *ep) · line 267
Quoted 11 lines
ref-filter.c +2
-1@@ -260,7 +260,8 @@ int parse_ref_filter_atom(const char *atom, const char *ep)* table. */ arg =memchr (sp,':' , ep - sp); -if ((!arg || len == arg - sp) && +if ((( arg && len == arg - sp) || + (!arg && len == ep - sp )) && !memcmp (valid_atom[i].name, sp, len))break ; }Your fix is pretty easy to to read and seems correct. Karthik's fix required several re-reads, and I *think* it may be correct, however, it's difficult to grok due to its logic inversion.
True, its not so easy to comprehend at first.
Quoted 9 lines
Aside from the two proposed fixes, a fix patterned after the original code which patch 5/12 replaced would be even easier to understand. That is, something like this:
arg = memchr(...); if (!arg) arg = ep; if (len == arg - sp && !memcmp(...)) ...
This seems good, will change, Thanks to both of you
Signature · 2 lines
Regards, Karthik Nayak