From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29504 invoked by alias); 29 Jul 2019 14:38:22 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 29492 invoked by uid 89); 29 Jul 2019 14:38:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-18.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1718 X-Spam-Status: No, score=-18.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Jul 2019 14:38:20 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EFBB3082D6C; Mon, 29 Jul 2019 14:38:19 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-117-20.ams2.redhat.com [10.36.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AA0A15D6A0; Mon, 29 Jul 2019 14:38:18 +0000 (UTC) From: Florian Weimer To: Mark Wielaard Cc: elfutils-devel@sourceware.org, Panu Matilainen Subject: Re: [PATCH] elfclassify tool References: <87k1fz8c9q.fsf@oldenburg2.str.redhat.com> <2e6a27c552ae5e365db54ca6b432c77c9ad5b041.camel@klomp.org> <871s22yybt.fsf@oldenburg2.str.redhat.com> <8736mfzhob.fsf@oldenburg2.str.redhat.com> <87k1cadpym.fsf@oldenburg2.str.redhat.com> <20190726221124.GA39429@wildebeest.org> <87a7cx6w0g.fsf@oldenburg2.str.redhat.com> <20190729143441.GC2881@wildebeest.org> Date: Mon, 29 Jul 2019 14:38:00 -0000 In-Reply-To: <20190729143441.GC2881@wildebeest.org> (Mark Wielaard's message of "Mon, 29 Jul 2019 16:34:41 +0200") Message-ID: <87pnls29eu.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 29 Jul 2019 14:38:19 +0000 (UTC) X-IsSubscribed: yes X-SW-Source: 2019-q3/txt/msg00092.txt.bz2 * Mark Wielaard: > On Mon, Jul 29, 2019 at 11:16:31AM +0200, Florian Weimer wrote: >> * Mark Wielaard: >> >> > +/* Called to process standard input if flag_stdin is not no_stdin. */ >> > +static void >> > +process_stdin (int *status) >> > +{ >> > + char delim; >> > + if (flag_stdin == do_stdin0) >> > + delim = '\0'; >> > + else >> > + delim = '\n'; >> > + >> > + char *buffer = NULL; >> > + size_t buffer_size = 0; >> > + while (true) >> > + { >> > + ssize_t ret = getdelim (&buffer, &buffer_size, delim, stdin); >> > + if (ferror (stdin)) >> > + { >> > + current_path = NULL; >> > + issue (errno, N_("reading from standard input")); >> > + break; >> > + } >> > + if (feof (stdin)) >> > + break; >> > + if (ret < 0) >> > + abort (); /* Cannot happen due to error checks above. */ >> > + if (delim != '\0' && ret > 0) >> > + buffer[ret - 1] = '\0'; >> >> I think this can overwrite the last character of the last line if the >> file does not end with '\n'. > > I see. "The buffer is null-terminated and includes the newline > character, if one was found." > > So the test should be: > > diff --git a/src/elfclassify.c b/src/elfclassify.c > index ebd42c1d5..b17d14d45 100644 > --- a/src/elfclassify.c > +++ b/src/elfclassify.c > @@ -862,7 +862,7 @@ process_stdin (int *status) > break; > if (ret < 0) > abort (); /* Cannot happen due to error checks above. */ > - if (delim != '\0' && ret > 0) > + if (delim != '\0' && ret > 0 && buffer[ret - 1] == '\n') > buffer[ret - 1] = '\0'; > current_path = buffer; > process_current_path (status); Right. But now I wonder why ret == 0 can ever happen. Maybe on OpenVMS, which doesn't use in-band signaling for line terminators? Thanks, Florian