bugGNUstep - Bugs: bug #35669, Garbage description string in...

Group
 
 

bug #35669: Garbage description string in POSIX NSErrors

Submitter:  Jens Alfke <snej>
Submitted:  Wed 29 Feb 2012 07:42:47 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  In Test
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 01 Mar 2012 07:35:31 PM UTC, comment #1: 

Should have been fixed by ensuring _GNU_SOURCE is not defined.
Please try it.

Richard Frith-Macdonald <CaS>
Group Member
Wed 29 Feb 2012 07:42:47 PM UTC, original submission:  

I am getting NSErrors with garbage description strings back from NSFileManager. (To be clear: the error is expected, and the domain and code are correct, but the description string in the userInfo is a large block of garbage.)

The cause appears to be a bug in +[NSError _lastError] in NSError+GNUstepBase.m. It calls strerror_r to get an error message, but that call isn’t filling in the char[] buffer.

Reading the man page tells me that there are two versions of strerror_r (a GNU one and a POSIX one) with different return types — the GNU version returns the string its return value and doesn’t always copy it into the buffer. What seems to be happening is that the method thinks it’s calling the POSIX version, but it’s actually calling the GNU version. So the error message in the return value is ignored, and instead it uses the buffer which wasn’t initialized.

I’m not sure what the best way is to fix this. It looks like one could either add
#undef _GNU_SOURCE
near the top of the file where it defines _XOPEN_SOURCE; or one could use an #if around the call to strerror_r to call either version depending on which one is available.

I have experimentally tried the latter, adding code that uses the non-POSIX version of strerror_r, and that fixes the problem.

CONFIGURATION

URL: http://svn.gna.org/svn/gnustep/libs/base/trunk/Source
Repository Root: http://svn.gna.org/svn/gnustep
Repository UUID: 72102866-910b-0410-8b05-ffd578937521
Revision: 34837

My OS is Ubuntu 11 (current according to software update).
I'm compiling with Clang 3.1 (trunk 151546).

Jens Alfke <snej>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by snej (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-03-01 CaS StatusNone Fixed
        Open/ClosedOpen In Test

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code