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.

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.

> Signed-off-by: Justus Winter <4winter at informatik.uni-hamburg.de>
> ---
>  mime-node.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mime-node.c b/mime-node.c
> index 97e8b48..839737a 100644
> --- a/mime-node.c
> +++ b/mime-node.c
> @@ -291,7 +291,7 @@ mime_node_child (mime_node_t *parent, int child)
>      GMimeObject *sub;
>      mime_node_t *node;
>  
> -    if (!parent || child < 0 || child >= parent->nchildren)
> +    if (!parent || !parent->part || child < 0 || child >= parent->nchildren)
>       return NULL;
>  
>      if (GMIME_IS_MULTIPART (parent->part)) {

Reply via email to