Commit graph

6 commits

Author SHA1 Message Date
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
rsc
cbeb0b26e4 Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. 2006-04-01 19:24:03 +00:00
rsc
74fc94d47e add dsa x509 2005-02-13 18:35:11 +00:00
rsc
1b1434ebce changes from plan 9. some clean-up. 2004-12-26 23:59:10 +00:00
rsc
be22ae2d07 SunOS can rot in hell. 2004-03-26 01:59:35 +00:00
rsc
0fc65b37a1 Add most of libsec. 2004-03-21 14:04:56 +00:00