Bug 51891 - class_copyIvarList crashes on empty ivars
Summary: class_copyIvarList crashes on empty ivars
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libobjc (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-18 09:53 UTC by Tilo Prütz
Modified: 2015-01-09 18:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 5.0
Known to fail: 4.9.3
Last reconfirmed:


Attachments
simple example (206 bytes, text/x-objcsrc)
2012-01-18 09:53 UTC, Tilo Prütz
Details
A patch that fixes the issue and provides a suitable testcase. (460 bytes, patch)
2014-12-24 16:28 UTC, Dimitris Papavasiliou
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tilo Prütz 2012-01-18 09:53:03 UTC
Created attachment 26361 [details]
simple example

When calling class_copyIvarList(class, NULL) with a class that has no ivars the app crashes with a segfault.

Please find an example attached.
Comment 1 Dimitris Papavasiliou 2012-09-16 15:21:04 UTC
The runtime crashes at libobj.c/ivars.c line 191:

count = ivar_list->ivar_count;

The problem is that, when a class has no instance variables ivar_list will be NULL so this needs to be checked for.
Comment 2 Larry Campbell 2014-12-08 21:31:40 UTC
Is anyone going to fix this? It is quite debilitating and there is no good workaround. Prior to gcc 4.6 one could include objc/deprecated/struct_objc_class.h and inspect ivar_list yourself before calling class_copyIvarList. Now that the ABI internals are private, this is no longer an option, and it's impossible to protect against.
Comment 3 Dimitris Papavasiliou 2014-12-24 16:28:11 UTC
Created attachment 34329 [details]
A patch that fixes the issue and provides a suitable testcase.
Comment 4 mrs@gcc.gnu.org 2015-01-09 18:13:24 UTC
Author: mrs
Date: Fri Jan  9 18:12:51 2015
New Revision: 219399

URL: https://gcc.gnu.org/viewcvs?rev=219399&root=gcc&view=rev
Log:
Added PR libobjc/51891.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libobjc/ChangeLog
Comment 5 mrs@gcc.gnu.org 2015-01-09 18:14:36 UTC
Fixed.