Red Hat Bugzilla – Bug 167722
C code written to use static string pointers to initialized strings from some function calls fails with a segmentation fault.
Last modified: 2007-11-30 17:11:13 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.10) Gecko/20050720 Fedora/1.0.6-1.1.fc4 Firefox/1.0.6
Description of problem:
Simple programs that use statically allocated strings are failing with segmentation faults due to, according to gdb, strlen function calls.
(I will attach a code snippet and gdb output that I have from the code runs).
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Compile code snippet (latest updated glibc)
2. Run program and see segmentation fault
Actual Results: Segmentation fault (core dumped)
Expected Results: The Time is: Wed Sep 7 11:26:51 2005
The Time is: Wed Sep 7 11:26:51 2005
STDOUT -- The Timeis: Wed Sep 7 11:26:51 2005
The time is: Wed Sep 7 11:26:51 2005
Where the time would change at every program invocation.
This did not start happening until after I did a yum update of a glibc change recently. The problem can be caused by using fprintf to any output, or if you use a static char string initialized by a function call (example, ctime), then it appears to crash all the time (the times I have tried, anyway).
Created attachment 118568 [details]
C code snippet that fails everytime on latest glibc update x86_64 bit Opteron
Created attachment 118569 [details]
GDB output from test case segmentation fault
This attachment is a gdb of the core file that I had when I ran my test case.
This is a bug in your testcase.
You should look at warnings GCC reports before filling bug reports.
On this testcase, GCC complains
warning: cast to pointer from integer of different size
char *time1 = (char *) ctime (¤t_time);
line. That's not too surprising, as ctime is prototyped not in sys/time.h,
but in time.h. And, without a prototype, the implicit prototype is
extern int ctime ();
so the upper 32 bits of time1 will be likely different from what you'd expect.