dynlink: avoid copying to temp buffer in get_lfs64

while commit 53ac44ff4c fixed the temp
buffer being undersized, the use of a temp buffer to begin with was a
mistake. instead, compare the requested symbol name in-place and use
the already-null-terminated copy of the name without "64" present in
lfs64_list[] to look up the real symbol.
This commit is contained in:
Rich Felker 2024-06-22 16:54:11 -04:00
parent 1b97d0060b
commit 50ab830633
1 changed files with 4 additions and 9 deletions

View File

@ -362,19 +362,14 @@ static struct symdef get_lfs64(const char *name)
"pwritev\0readdir\0scandir\0sendfile\0setrlimit\0"
"stat\0statfs\0statvfs\0tmpfile\0truncate\0versionsort\0"
"__fxstat\0__fxstatat\0__lxstat\0__xstat\0";
size_t l;
char buf[17];
for (l=0; name[l]; l++) {
if (l >= sizeof buf) goto nomatch;
buf[l] = name[l];
}
if (!strcmp(name, "readdir64_r"))
return find_sym(&ldso, "readdir_r", 1);
if (l<2 || name[l-2]!='6' || name[l-1]!='4')
size_t l = strnlen(name, 18);
if (l<2 || name[l-2]!='6' || name[l-1]!='4' || name[l])
goto nomatch;
buf[l-=2] = 0;
for (p=lfs64_list; *p; p++) {
if (!strcmp(buf, p)) return find_sym(&ldso, buf, 1);
if (!strncmp(name, p, l-2) && !p[l-2])
return find_sym(&ldso, p, 1);
while (*p) p++;
}
nomatch: