Bug 21412 - Bad error handling practice
Summary: Bad error handling practice
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other Linux (All)
: high major
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-26 04:49 UTC by Ilya Gorenbein
Modified: 2009-04-26 12:24 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Ilya Gorenbein 2009-04-26 04:49:59 UTC
Hello!

At Object.h we have two macros:

#define OBJECT_TYPE_CHECK(wanted_type) \
    if (unlikely(type != wanted_type)) { \
        error(0, "Call to Object where the object was type %d, " \
                 "not the expected type %d", type, wanted_type); \
        abort(); \
    }

#define OBJECT_2TYPES_CHECK(wanted_type1, wanted_type2) \
    if (unlikely(type != wanted_type1) && unlikely(type != wanted_type2)) { \
        error(0, "Call to Object where the object was type %d, " \
                 "not the expected type %d or %d", type, wanted_type1, wanted_type2); \
        abort(); \
    }

The purpose of these macros is obvious. But, in case of type inconsistency it is too stiff to abort the WHOLE hosting application. I suggest handling it either using template functions or treatment per case. For example:

Instead of: 
Dict *getDict() { OBJECT_TYPE_CHECK(objDict); return dict; }

Dict *getDict() 
{
	 if (unlikely(type != wanted_type)) 
	{ 
	        error(0, "Call to Object where the object was type %d, "  "not the expected type %d", type, wanted_type); 
	        return NULL;
	 }

	 return dict; 
}


Please, let me know if this approach is acceptable to you, and if “yes” I can supply the patch.


Regards,
Ilya Gorenbein
Comment 1 Albert Astals Cid 2009-04-26 12:24:37 UTC
No, patch is not acceptable.

Your patch still will take down the whole application, you are returning a NULL pointer that will make poppler crash.

If you found any place where this is happening just fix it the proper way, that is calling the isFoo before getFoo.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.