[PATCH 2/2] Avoid potentially dereferencing a NULL pointer

Justus Winter 4winter at informatik.uni-hamburg.de
Mon Sep 24 05:55:10 PDT 2012


Quoting Austin Clements (2012-09-22 18:19:08)
> Quoth Justus Winter on Sep 21 at  2:50 pm:
> > GMIME_IS_MULTIPART and GMIME_IS_MESSAGE both handle NULL pointers
> > gracefully, but the G_OBJECT_TYPE used in the error handling block
> > dereferences it without checking it first.
> > 
> > Fix this by checking whether parent->part is valid.
> > 
> > Found using the clang static analyzer.
> 
> Neat.

Yes. Besides this the code turns up no warnings (modulo one false
positive, clang doesn't understand that progress_notify is never
called if it's NULL in notmuch_database_upgrade b/c the signal handler
isn't set up then).

> Can this actually happen, though?  If so, I think this point is too
> late to be checking for a NULL part field.  It should probably be
> checked when the mime_node_t is created so that mime_node_t never has
> a NULL part field.

I'm not sure actually. Then again this patch isn't hacky at all and
being somewhat defensive isn't bad imho.

Justus


More information about the notmuch mailing list