summaryrefslogtreecommitdiff
path: root/mailinfo.c
diff options
context:
space:
mode:
authorAndrei Rybak <rybak.a.v@gmail.com>2021-06-08 20:48:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-09 02:13:07 (GMT)
commit4184cbd635140e83c5f0d57c377eec93a9b6eedf (patch)
tree1b8c6fd04164a9de09bd677ce6caa997e6b25c75 /mailinfo.c
parent48bf2fa8bad054d66bd79c6ba903c89c704201f7 (diff)
downloadgit-4184cbd635140e83c5f0d57c377eec93a9b6eedf.zip
git-4184cbd635140e83c5f0d57c377eec93a9b6eedf.tar.gz
git-4184cbd635140e83c5f0d57c377eec93a9b6eedf.tar.bz2
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>
Diffstat (limited to 'mailinfo.c')
-rw-r--r--mailinfo.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/mailinfo.c b/mailinfo.c
index 5681d91..6f3bb5a 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -705,8 +705,8 @@ static int is_scissors_line(const char *line)
perforation++;
continue;
}
- if ((!memcmp(c, ">8", 2) || !memcmp(c, "8<", 2) ||
- !memcmp(c, ">%", 2) || !memcmp(c, "%<", 2))) {
+ if (starts_with(c, ">8") || starts_with(c, "8<") ||
+ starts_with(c, ">%") || starts_with(c, "%<")) {
in_perforation = 1;
perforation += 2;
scissors += 2;