Bug 427673 - valgrind errors in strftime if tm.tm_hour not set
valgrind errors in strftime if tm.tm_hour not set
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: glibc (Show other bugs)
8
All Linux
low Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-01-06 11:10 EST by Jonathan Wakely
Modified: 2008-04-10 06:11 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-04-10 06:11:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
testcase (231 bytes, text/x-csrc)
2008-01-06 11:10 EST, Jonathan Wakely
no flags Details
patch to avoid referencing tm_hour too early (703 bytes, patch)
2008-01-06 11:13 EST, Jonathan Wakely
no flags Details | Diff

  None (edit)
Description Jonathan Wakely 2008-01-06 11:10:46 EST
Description of problem:
Valgrind's memcheck tool reports memory errors from strftime if tm.tm_hour is
uninitialised, even when no conversion specifier requires the tm_hour field.

Version-Release number of selected component (if applicable):
glibc-2.7-2

How reproducible:
Always

Steps to Reproduce:
Compile the attached testcase and run it with valgrind
  
Actual results:

$ gcc strftime.c -g && valgrind ./a.out
==5166== Memcheck, a memory error detector.
==5166== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==5166== Using LibVEX rev 1732, a library for dynamic binary translation.
==5166== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==5166== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
==5166== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==5166== For more details, rerun with: -v
==5166==
==5166== Conditional jump or move depends on uninitialised value(s)
==5166==    at 0x32F889213D: __strftime_internal (strftime_l.c:578)
==5166==    by 0x4004DD: main (strftime.c:10)
==5166==
==5166== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 1)
==5166== malloc/free: in use at exit: 0 bytes in 0 blocks.
==5166== malloc/free: 8 allocs, 8 frees, 3,048 bytes allocated.
==5166== For counts of detected errors, rerun with: -v
==5166== All heap blocks were freed -- no leaks are possible.

After initialising tm_hour the second strftime call gives no error.


Expected results:
No memcheck errors. 

Additional info:

The reference is on line 578 of strftime_l.c - tm_hour is copied into hour12 and
then that is used in a condition.  hour12 doesn't actually affect the output
unless tm_hour is used, but by then it's too late as valgrind has already
complained.
Comment 1 Jonathan Wakely 2008-01-06 11:10:46 EST
Created attachment 290917 [details]
testcase
Comment 2 Jonathan Wakely 2008-01-06 11:13:49 EST
Created attachment 290918 [details]
patch to avoid referencing tm_hour too early

something like this is needed to delay any dependency on tm_hour
Comment 3 Jakub Jelinek 2008-04-10 06:11:04 EDT
glibc will not change just to shut up valgrind.  There is no bug in this case.

Note You need to log in before you can comment on or make changes to this bug.