Implement more security stuff

- Support deterministic stacks on OpenBSD
- Support OpenBSD system call origin verification
- Fix overrun by one in chibicc string token allocator
- Get all chibicc tests passing under Address Sanitizer
This commit is contained in:
Justine Tunney 2021-02-02 20:21:06 -08:00
parent cbfd4ccd1e
commit c843243322
56 changed files with 376 additions and 245 deletions

View file

@ -17,15 +17,21 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/str.h"
#include "libc/str/tinymemmem.internal.h"
/**
* Naïve substring search implementation.
* @see libc/alg/memmem.c
*/
void *tinymemmem(const void *haystk, size_t haystksize, const void *needle,
void *tinymemmem(const void *haystack, size_t haystacksize, const void *needle,
size_t needlesize) {
return (/*unconst*/ void *)tinymemmemi(
(const unsigned char *)haystk, haystksize, (const unsigned char *)needle,
needlesize);
size_t i;
const char *p, *pe;
for (p = haystack, pe = p + haystacksize; p < pe;) {
for (++p, i = 0;;) {
if (++i > needlesize) return p - 1;
if (p == pe) break;
if (((const char *)needle)[i - 1] != (p - 1)[i - 1]) break;
}
}
return !haystacksize && !needlesize ? haystack : NULL;
}