This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] elfclassify tool


* 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]