Bug 21062

Summary: SIGSEGV when mmap() fails
Product: fontconfig Reporter: Serge van den Boom <svdb+freedesktop.org>
Component: libraryAssignee: Keith Packard <keithp>
Status: RESOLVED FIXED QA Contact: Behdad Esfahbod <freedesktop>
Severity: normal    
Priority: medium CC: freedesktop
Version: 2.6Keywords: patch
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Fix

Description Serge van den Boom 2009-04-05 09:57:32 UTC
Created attachment 24582 [details] [review]
Fix

In fccache.c, there is the line
    cache = mmap (0, fd_stat->st_size, PROT_READ, MAP_SHARED, fd, 0);
Furtheron there is the check
    if (!cache)
But mmap() returns MAP_FAILED on failure, which is (void *) -1, and not NULL. So if mmap() fails, the guard of that if-statement will evaluate to false, and no cache is allocated, resulting in a crash a few lines later at
    if (cache->magic != FC_CACHE_MAGIC_MMAP
Comment 1 Behdad Esfahbod 2009-04-05 16:00:53 UTC
Oops.  Thanks for the patch.  In my tree now.
Comment 2 Behdad Esfahbod 2009-06-24 12:36:02 UTC
I believe I've fixed this in 2.7.0.  Please reopen otherwise.

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.