public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/28038] New: getdelim()/getline() does not add NUL terminator if first character is EOF.
@ 2021-06-30 21:43 me at duckie dot co
  2021-06-30 21:44 ` [Bug stdio/28038] " me at duckie dot co
  0 siblings, 1 reply; 2+ messages in thread
From: me at duckie dot co @ 2021-06-30 21:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28038

            Bug ID: 28038
           Summary: getdelim()/getline() does not add NUL terminator if
                    first character is EOF.
           Product: glibc
           Version: 2.28
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: me at duckie dot co
  Target Milestone: ---

Created attachment 13520
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13520&action=edit
Testcase (run with: printf '' | valgrind ./testcase)

According to IEEE Std 1003.1-2017 (
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html ):

> The characters read, including any delimiter, shall be stored in the object,
> and a terminating NUL added when the delimiter or end-of-file is encountered.

However, if the first character is an end-of-file, the first character of the
line should be a NUL -- instead, it's uninitialized.

Looking at the source, it appears this is still a problem:
https://sourceware.org/git/?p=glibc.git;a=blob;f=libio/iogetdelim.c;hb=HEAD

I have attached a testcase. If you compile the testcase (gcc -Wall -Werror
-pedantic testcase.c -o testcase), then do `printf '' | valgrind
--track-origins=yes ./testcase`, you get the following:


puppy@cerberus:~/boreutils$ printf '' | valgrind --track-origins=yes ./testcase
==2904== Memcheck, a memory error detector
==2904== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2904== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==2904== Command: ./testcase
==2904== 
bytes_read = -1, line = '77709376'
==2904== Conditional jump or move depends on uninitialised value(s)
==2904==    at 0x4838C65: strlen (vg_replace_strmem.c:460)
==2904==    by 0x48A99EE: vfprintf (vfprintf.c:1638)
==2904==    by 0x48B0605: printf (printf.c:33)
==2904==    by 0x4011CE: main (in /home/puppy/boreutils/testcase)
==2904==  Uninitialised value was created by a heap allocation
==2904==    at 0x483577F: malloc (vg_replace_malloc.c:299)
==2904==    by 0x48C8C2E: getdelim (iogetdelim.c:62)
==2904==    by 0x401183: main (in /home/puppy/boreutils/testcase)
==2904== 
> (bytes_read == -1 && line != NULL): ''
==2904== 
==2904== HEAP SUMMARY:
==2904==     in use at exit: 0 bytes in 0 blocks
==2904==   total heap usage: 3 allocs, 3 frees, 5,240 bytes allocated
==2904== 
==2904== All heap blocks were freed -- no leaks are possible
==2904== 
==2904== For counts of detected and suppressed errors, rerun with: -v
==2904== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
puppy@cerberus:~/boreutils$

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug stdio/28038] getdelim()/getline() does not add NUL terminator if first character is EOF.
  2021-06-30 21:43 [Bug stdio/28038] New: getdelim()/getline() does not add NUL terminator if first character is EOF me at duckie dot co
@ 2021-06-30 21:44 ` me at duckie dot co
  0 siblings, 0 replies; 2+ messages in thread
From: me at duckie dot co @ 2021-06-30 21:44 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=28038

me at duckie dot co changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |me at duckie dot co

--- Comment #1 from me at duckie dot co ---
Created attachment 13521
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13521&action=edit
Untested patch that *should* fix the problem.

Here's a patch that *should* fix the problem, but I haven't tested (since I
don't know how).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-30 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 21:43 [Bug stdio/28038] New: getdelim()/getline() does not add NUL terminator if first character is EOF me at duckie dot co
2021-06-30 21:44 ` [Bug stdio/28038] " me at duckie dot co

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).