[fprint] patches: baby steps: fix some NULL pointer handling

Jason Gerard DeRose jason at system76.com
Fri Aug 21 14:45:08 PDT 2015


As part of helping me understand the libfprint code, I ran scan-build
and fixed one NULL pointer dereference it reported, which after tracing
that back led to another small fix.

0001_fix_NULL_pointer_dereference_in_vfs5001_submit_image.patch
===============================================================
submit_image() in drivers/vfs5001.c checks whether `img` is NULL, but
was missing a return at the end of the conditional block, so it would
still go on to dereference the NULL pointer when setting `img->flags`,
`img->width`, and `img->height`.

This was caught by scan-build and I confirmed that scan-build no longer
reported an error here after the fix.


0002-fpi_img_new_assumes_g_malloc0_succeeds.patch
=================================================
fpi_img_new() in img.c assumes that g_malloc0() always succeeds, for
which there is no guarantee.

So if g_malloc0() fails (returns NULL), fpi_img_new() should abort and
return NULL, should not set `img->length`.

Likewise, fpi_img_new_for_imgdev() should check whether fpi_img_new()
returns NULL, and if it does, fpi_img_new_for_imgdev() should abort and
return NULL, should not set `img->width`, `img->height`.

The next step, of course, is making sure all fpi_img_new(),
fpi_img_new_for_imgdev() consumers check for a NULL return value and do
the right thing.  A task I haven't tackled yet.


Please guide me on preferred patch workflow style!
==================================================

If I haven't submitted these patches in an acceptable form, or if you
would like me to do it differently next time, please let me know!

I'm still trying to find my way around here, don't really know the best
approach yet :D

Cheers,
Jason
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001_fix_NULL_pointer_dereference_in_vfs5001_submit_image.patch
Type: text/x-patch
Size: 737 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/fprint/attachments/20150821/543506c3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-fpi_img_new_assumes_g_malloc0_succeeds.patch
Type: text/x-patch
Size: 1097 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/fprint/attachments/20150821/543506c3/attachment-0001.bin>


More information about the fprint mailing list