bugGNUstep - Bugs: bug #35477, -[NSValue description]...

Group
 
 

bug #35477: -[NSValue description] dereferences nonretained pointers

Submitter:  Dag Ågren <waha_06x36>
Submitted:  Wed 08 Feb 2012 02:42:42 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 08 Feb 2012 03:35:39 PM UTC, comment #1: 

Thanks very much.  I make the suggested change in svn.

Richard Frith-Macdonald <CaS>
Group Member
Wed 08 Feb 2012 02:42:42 PM UTC, original submission:  

Calling description on an NSValue created with valueWithNonretainedPointer: causes the pointer to be dereferenced, and its desription method to be called. This is not safe, and causes crashes under several different conditions.

First, the object may have been released. This would make it unsafe to grab the actual pointer and use it, but calling description should still be safe.

Second, NSValues are often used for breaking retain cycles in complex data structures. Calling description on the referenced object in this case can cause an endless loop which blows the stack.

Included is a test program with two statements that crash. Neither should crash under these circumstances.

The fix is straightforward: Remove the call to description on the contained object, and merely print the numerical value of the contained pointer. This matches the behaviour of Cocoa on OS X.

Dag Ågren <waha_06x36>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #25021:  test.m added by waha_06x36 (617B - text/x-objcsrc)

 

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 waha_06x36 (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-02-08 CaS StatusNone Fixed
        Open/ClosedOpen Closed
    2012-02-08 waha_06x36 Attached File- Added test.m, #25021

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code