mailinfo: use starts_with() when checking scissors
Existing checks for scissors characters using memcmp(3) never read past the end of the line, because all substrings we are interested in are two characters long, and the outer loop guarantees we have at least one character. So at most we will look at the NUL. However, this is too subtle and may lead to bugs in code which copies this behavior without realizing substring length requirement. So use starts_with() instead, which will stop at NUL regardless of the length of the prefix. Remove extra pair of parentheses while we are here. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Andrei Rybak <rybak.a.v@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andrei Rybak committed
Jun 8, 2021 at 22:48 UTC
4184cbd635140e83c5f0d57c377eec93a9b6eedf
1 file changed
+2
-2
mailinfo.c
+2
-2
@@ -705,8 +705,8 @@ static int is_scissors_line(const char *line)
705
perforation++;
706
continue;
707
}
708
- if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
709
- !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
708
+ if (starts_with(c, ">8") || starts_with(c, "8<") ||
709
+ starts_with(c, ">%") || starts_with(c, "%<")) {
710
in_perforation = 1;
711
perforation += 2;
712
scissors += 2;