plan9port/src/libsec/port
Xi Wang 8a2a5b8f25 libsec: avoid undefined C
gcc compiles `p + length < p' into 'length < 0' since pointer overflow is undefined behavior in C.  This breaks the check against a large `length'.

Use `length > pend - p' instead.

There's no need to check `length < 0' since `length' is from length_decode() and should be non-negative.

===

Try the simplified code.

void bar(void);
void foo(unsigned char *p, int length)
{
        if (p + length < p)
                bar();
}

$ gcc -S -o - t.c -O2
...
foo:
.LFB0:
        .cfi_startproc
        testl	%esi, %esi
        js	.L4
        rep
        ret
.L4:
        jmp	bar
        .cfi_endproc

Clearly `p' is not used at all.

R=rsc
CC=plan9port.codebot
https://codereview.appspot.com/7231069
2013-03-19 14:35:16 -04:00
..
aes.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
blowfish.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
decodepem.c changes from plan 9. some clean-up. 2004-12-26 23:59:10 +00:00
des3CBC.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
des3ECB.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
des.c add libsec 2003-11-23 18:21:42 +00:00
desCBC.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
desECB.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
desmodes.c add libsec 2003-11-23 18:21:42 +00:00
dsaalloc.c Add most of libsec. 2004-03-21 14:04:56 +00:00
dsagen.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
dsaprimes.c libsec: fix dsagen 64-bit bug 2011-10-05 16:23:01 -04:00
dsaprivtopub.c Add most of libsec. 2004-03-21 14:04:56 +00:00
dsasign.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
dsaverify.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
egalloc.c Add most of libsec. 2004-03-21 14:04:56 +00:00
egdecrypt.c Add most of libsec. 2004-03-21 14:04:56 +00:00
egencrypt.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
eggen.c Add most of libsec. 2004-03-21 14:04:56 +00:00
egprivtopub.c Add most of libsec. 2004-03-21 14:04:56 +00:00
egsign.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
egtest.c Add most of libsec. 2004-03-21 14:04:56 +00:00
egverify.c Add most of libsec. 2004-03-21 14:04:56 +00:00
fastrand.c add libsec 2003-11-23 18:21:42 +00:00
genprime.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
genrandom.c Small tweaks 2004-03-21 04:33:13 +00:00
gensafeprime.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
genstrongprime.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
hmac.c Add most of libsec. 2004-03-21 14:04:56 +00:00
hmactest.c Add most of libsec. 2004-03-21 14:04:56 +00:00
md4.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
md4test.c Add most of libsec. 2004-03-21 14:04:56 +00:00
md5.c Make things build on FreeBSD again. 2003-11-23 20:04:53 +00:00
md5block.c add libsec 2003-11-23 18:21:42 +00:00
md5pickle.c changes from plan 9. some clean-up. 2004-12-26 23:59:10 +00:00
mkfile more tomfoolery. 2004-04-21 06:53:59 +00:00
nfastrand.c Add most of libsec. 2004-03-21 14:04:56 +00:00
os.h add libsec 2003-11-23 18:21:42 +00:00
portdate add portdate 2004-12-26 23:59:30 +00:00
primetest.c libsec: update primetest to use mpfmt 2010-03-11 18:04:12 -08:00
prng.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
probably_prime.c probably_prime: run more than one Miller-Rabin round 2010-03-11 18:04:42 -08:00
rc4.c Add most of libsec. 2004-03-21 14:04:56 +00:00
readcert.c changes from plan 9. some clean-up. 2004-12-26 23:59:10 +00:00
reduce Libsec doesn't compile without a reduce script, either. 2004-04-21 17:52:08 +00:00
rsaalloc.c Add most of libsec. 2004-03-21 14:04:56 +00:00
rsadecrypt.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
rsaencrypt.c Add most of libsec. 2004-03-21 14:04:56 +00:00
rsafill.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
rsagen.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
rsaprivtopub.c Add most of libsec. 2004-03-21 14:04:56 +00:00
rsatest.c Add most of libsec. 2004-03-21 14:04:56 +00:00
sha1.c Small tweaks 2004-03-21 04:33:13 +00:00
sha1block.c Small tweaks 2004-03-21 04:33:13 +00:00
sha1pickle.c Add most of libsec. 2004-03-21 14:04:56 +00:00
smallprimes.c Add most of libsec. 2004-03-21 14:04:56 +00:00
smallprimetest.c Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
thumb.c Add most of libsec. 2004-03-21 14:04:56 +00:00
tlshand.c fix clang warnings reported by Tuncer Ayaz 2012-10-21 11:25:08 -04:00
x509.c libsec: avoid undefined C 2013-03-19 14:35:16 -04:00