From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26595 invoked from network); 11 Nov 2020 11:25:17 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 11 Nov 2020 11:25:17 -0000 Received: (qmail 28200 invoked by uid 550); 11 Nov 2020 11:25:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 28179 invoked from network); 11 Nov 2020 11:25:12 -0000 Date: Wed, 11 Nov 2020 12:25:00 +0100 From: Szabolcs Nagy To: Alexey Izbyshev Cc: musl@lists.openwall.com Message-ID: <20201111112500.GI1370092@port70.net> Mail-Followup-To: Alexey Izbyshev , musl@lists.openwall.com References: <20201030185716.GE534@brightrain.aerifal.cx> <5298816.XTEcGr0bgB@nanabozho> <20201031033117.GH534@brightrain.aerifal.cx> <20201106033616.GX534@brightrain.aerifal.cx> <20201108161215.GE1370092@port70.net> <20201109170729.GA534@brightrain.aerifal.cx> <20201109215901.GG1370092@port70.net> <20201109222320.GC534@brightrain.aerifal.cx> <20201111005216.GH534@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [musl] [PATCH v2] MT fork * Alexey Izbyshev [2020-11-11 09:35:22 +0300]: > 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. > > if we don't have to replicate a lot of code in ldso then this sounds good. > > +static ssize_t read_loop(int fd, void *p, size_t n) > > +{ > > + unsigned char *b = p; > > + for (size_t l, i=0; i > + l = read(fd, b+i, n-i); > > + if (l<0) { > > + if (errno==EINTR) continue; > This increments `i` by a negative `l`. it's worse: l cannot be negative so the error check is ineffective. maybe it should be ssize_t? or check == -1 > > + 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