From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27234 invoked by alias); 29 Jul 2019 14:34:46 -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 27224 invoked by uid 89); 29 Jul 2019 14:34:46 -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=-21.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-21.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_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: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 Jul 2019 14:34:45 +0000 Received: from librem.wildebeest.org (host81-133-75-206.in-addr.btopenworld.com [81.133.75.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 8DF1E308B2F5; Mon, 29 Jul 2019 16:34:43 +0200 (CEST) Received: by librem.wildebeest.org (Postfix, from userid 1000) id 354D5C01C0; Mon, 29 Jul 2019 16:34:41 +0200 (CEST) Date: Mon, 29 Jul 2019 14:34:00 -0000 From: Mark Wielaard To: Florian Weimer Cc: elfutils-devel@sourceware.org, Panu Matilainen Subject: Re: [PATCH] elfclassify tool Message-ID: <20190729143441.GC2881@wildebeest.org> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a7cx6w0g.fsf@oldenburg2.str.redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2019-q3/txt/msg00091.txt.bz2 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); Thanks, Mark