|
|
Message-ID: <ddd7b2bb1e02df633caa70c6dc90b7c5@ispras.ru>
Date: Wed, 11 Nov 2020 09:35:22 +0300
From: Alexey Izbyshev <izbyshev@...ras.ru>
To: musl@...ts.openwall.com
Subject: Re: [PATCH v2] MT fork
On 2020-11-11 03:52, Rich Felker wrote:
> Here's a proposed first patch in series, getting rid of getdelim/stdio
> usage in ldso. I think that suffices to set the stage for adding
> __libc_malloc, __libc_free, __libc_calloc, __libc_realloc and having
> ldso use them.
>
> +static ssize_t read_loop(int fd, void *p, size_t n)
> +{
> + unsigned char *b = p;
> + for (size_t l, i=0; i<n; i+=l) {
> + l = read(fd, b+i, n-i);
> + if (l<0) {
> + if (errno==EINTR) continue;
This increments `i` by a negative `l`.
> + else return -1;
> + }
> + if (l==0) return i;
> + }
> + return n;
> +}
> + if (fd>=0) {
> + size_t n = 0;
> + if (!fstat(fd, &st)) n = st.st_size;
> + sys_path = malloc(n+1);
> + sys_path[n] = 0;
`sys_path` can be NULL here.
> + if (!sys_path || read_loop(fd, sys_path, n)<0) {
> free(sys_path);
> sys_path = "";
> }
> - fclose(f);
> + close(fd);
> } else if (errno != ENOENT) {
> sys_path = "";
> }
Alexey
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.