Bug 131419

Summary: wcswcs returns invalid address
Product: Red Hat Enterprise Linux 3 Reporter: Need Real Name <ssurve>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: high Docs Contact:
Priority: medium    
Version: 3.0   
Target Milestone: ---   
Target Release: ---   
Hardware: ia64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-09-01 04:59:25 EDT Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Attachments:
Description Flags
C program none

Description Need Real Name 2004-09-01 03:14:56 EDT
Description of problem:
wchar_t *wcswcs(wchar_t *, wchar_t *) does not return valid address.

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

glibc-2.3.2-95.6
gcc-3.2.3-24
Architecture used is Itanium 2.

How reproducible:
Please find the test case attached to this bug report.

Steps to Reproduce:
1. Compile the C test case using:
gcc test.c
2. Run the executable a.out
./a.out

  
Actual results:
Segmentation fault (core dumped)

Expected results:
Len=3

Additional info:
The same test case works on i686 and fails on ia64
Comment 1 Need Real Name 2004-09-01 03:18:00 EDT
Created attachment 103331 [details]
C program

This is a C program to reproduce the problem
Comment 2 Jakub Jelinek 2004-09-01 04:59:25 EDT
It always help to compile with warnings enabled.
gcc -Wall test.c
test.c: In function `main':
test.c:13: warning: implicit declaration of function `mbstowcs'
test.c:17: warning: implicit declaration of function `wcswcs'
test.c:17: warning: assignment makes pointer from integer without a cast
test.c:31: warning: implicit declaration of function `wcstombs'
test.c:32: warning: implicit declaration of function `strlen'
test.c:33: warning: int format, different type arg (arg 2)

makes it clear that you are missing some includes
(particularly
#include <string.h>
#include <stdlib.h>
) and also, given that wcswcs is a X/Open only function (ISO C99
uses wcsstr), you need to enable X/Open feature set, see info libc
on Feature Set Macros.
I.e. if you add those two includes and compile with -D_XOPEN_SOURCE,
-D_GNU_SOURCE, -D_XOPEN_SOURCE=600 or similar, it will work just fine.

Unprototyped functions are assumed to return int, so really bad things
happen on 64-bit arches for functions which return pointers or other
64-bit values or on all arches if they return floating point values
and prototypes aren't used.