feature(libqasan): add strndup (#1860)

* feature(libqasan): add asprintf and vasprintf

* feature(libqasan): add asprintf and vasprintf to hotpatch

* feature(libqasan): add strndup
This commit is contained in:
Rubens Brandão 2024-02-15 12:13:46 -03:00 committed by GitHub
parent d6d6a23f69
commit 97a83aba3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -471,6 +471,21 @@ char *strdup(const char *s) {
return r; return r;
} }
char *strndup(const char *s, size_t n) {
void *rtv = __builtin_return_address(0);
QASAN_DEBUG("%14p: strndup(%p, %zu)\n", rtv, s, n);
size_t l = __libqasan_strnlen(s, n);
if (l > n) { l = n; }
QASAN_LOAD(s, l + 1);
void *r = __libqasan_malloc(l + 1);
__libqasan_memcpy(r, s, l);
((char*)r)[l] = 0;
QASAN_DEBUG("\t\t = %p\n", r);
return r;
}
size_t strlen(const char *s) { size_t strlen(const char *s) {
void *rtv = __builtin_return_address(0); void *rtv = __builtin_return_address(0);

View File

@ -214,6 +214,7 @@ void __libqasan_hotpatch(void) {
HOTPATCH(strncpy) HOTPATCH(strncpy)
HOTPATCH(stpcpy) HOTPATCH(stpcpy)
HOTPATCH(strdup) HOTPATCH(strdup)
HOTPATCH(strndup)
HOTPATCH(strlen) HOTPATCH(strlen)
HOTPATCH(strnlen) HOTPATCH(strnlen)
HOTPATCH(strstr) HOTPATCH(strstr)