]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/receive-pack: fix incorrect pointer arithmetic
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 26 Mar 2017 16:01:28 +0000 (16:01 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2017 16:57:14 +0000 (09:57 -0700)
If we had already processed the last newline in a push certificate, we
would end up subtracting NULL from the end-of-certificate pointer when
computing the length of the line.  This would have resulted in an
absurdly large length, and possibly a buffer overflow.  Instead,
subtract the beginning-of-certificate pointer from the
end-of-certificate pointer, which is what's expected.

Note that this situation should never occur, since not only do we
require the certificate to be newline terminated, but the signature will
only be read from the beginning of a line.  Nevertheless, it seems
prudent to correct it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/receive-pack.c

index 42f25a5103a72486c46d7b3a584f249495dc12b4..df18eac9e45ef5744cd977caa57600af1dc14986 100644 (file)
@@ -1127,7 +1127,7 @@ static void queue_commands_from_cert(struct command **tail,
 
        while (boc < eoc) {
                const char *eol = memchr(boc, '\n', eoc - boc);
-               tail = queue_command(tail, boc, eol ? eol - boc : eoc - eol);
+               tail = queue_command(tail, boc, eol ? eol - boc : eoc - boc);
                boc = eol ? eol + 1 : eoc;
        }
 }