Fix stack abuse in llama.cc

This change also incorporates improvements for MODE=asan. It's been
confirmed that o/asan/third_party/ggml/llama.com will work.

Fixes #829
This commit is contained in:
Justine Tunney 2023-06-08 06:44:54 -07:00
parent 32682f0ce7
commit 4d629fd424
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 73 additions and 76 deletions

View file

@ -29,11 +29,13 @@
* @return is <0, 0, or >0 based on uint8_t comparison
* @asyncsignalsafe
*/
int strcmp(const char *a, const char *b) {
noasan int strcmp(const char *a, const char *b) {
int c;
size_t i = 0;
uint64_t v, w, d;
if (a == b) return 0;
if (IsAsan()) __asan_verify_str(a);
if (IsAsan()) __asan_verify_str(b);
if ((c = (*a & 255) - (*b & 255))) return c;
if (!IsTiny() && ((uintptr_t)a & 7) == ((uintptr_t)b & 7)) {
for (; (uintptr_t)(a + i) & 7; ++i) {
@ -53,10 +55,6 @@ int strcmp(const char *a, const char *b) {
} else {
while (a[i] == b[i] && b[i]) ++i;
}
if (IsAsan()) {
__asan_verify(a, i + 1);
__asan_verify(b, i + 1);
}
return (a[i] & 255) - (b[i] & 255);
}