提交 8c203eae 编写于 作者: R Rich Felker

make dynamic linker accept : or \n as path separator

this allows /etc/ld-musl-$(ARCH).path to contain one path per line,
which is much more convenient for users than the :-delimited format,
which was a source of repeated and unnecessary confusion. for
simplicity, \n is also accepted in environment variables, though it
should probably not be used there.

at the same time, issues with overly long paths invoking UB or getting
truncated have been fixed. such issues should not have arisen with the
environment (which is size-limited) but could have been generated by a
path file larger than 2**31 bytes in length.
上级 7bec92e7
...@@ -403,16 +403,16 @@ error: ...@@ -403,16 +403,16 @@ error:
return 0; return 0;
} }
static int path_open(const char *name, const char *search, char *buf, size_t buf_size) static int path_open(const char *name, const char *s, char *buf, size_t buf_size)
{ {
const char *s=search, *z; size_t l;
int l, fd; int fd;
for (;;) { for (;;) {
while (*s==':') s++; s += strspn(s, ":\n");
if (!*s) return -1; l = strcspn(s, ":\n");
z = strchr(s, ':'); if (l-1 >= INT_MAX) return -1;
l = z ? z-s : strlen(s); if (snprintf(buf, buf_size, "%.*s/%s", (int)l, s, name) >= buf_size)
snprintf(buf, buf_size, "%.*s/%s", l, s, name); continue;
if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd; if ((fd = open(buf, O_RDONLY|O_CLOEXEC))>=0) return fd;
s += l; s += l;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册