[Fontconfig] [PATCH] fc-list: Exit with an error for invalid patterns

Akira TAGOH akira at tagoh.org
Mon Sep 23 19:16:46 PDT 2013


Thanks for catching this up. that should be fixed in
FcListPatternMatchAny so that it still likely happens after applying
your patch if one gives the null FcPattern to FcFontList() or so in
other applications. fixed in git this way.

On Sun, Sep 22, 2013 at 4:03 AM, W. Trevor King <wking at tremily.us> wrote:
> From: "W. Trevor King" <wking at tremily.us>
>
> Instead of segfaulting as we do now:
>
>   $ fc-list :charset=263A
>   Fontconfig error: Cannot load default config file
>   Segmentation fault (core dumped)
>   $ gdb fc-list core
>>   Core was generated by `fc-list :charset=263A'.
>   Program terminated with signal 11, Segmentation fault.
>   #0  0x00007f8b7903e7ca in FcListPatternMatchAny (p=0x0, font=0x1316568)
>       at fclist.c:215
>   215         for (i = 0; i < p->num; i++)
>   (gdb) bt
>   #0  0x00007f8b7903e7ca in FcListPatternMatchAny (p=0x0, font=0x1316568)
>       at fclist.c:215
>   #1  0x00007f8b7903f1a0 in IA__FcFontSetList (config=0x12da0c0,
>       sets=0x7fff4959f430, nsets=1, p=0x0, os=0x12da010) at fclist.c:513
>   #2  0x00007f8b7903f3b7 in IA__FcFontList (config=0x12da0c0, p=0x0,
>       os=0x12da010) at fclist.c:601
>   #3  0x0000000000401115 in main (argc=2, argv=0x7fff4959f598) at fc-list.c:157
>   (gdb) printf "%p\n", p
>   (nil)
>   (gdb) up 3
>   #3  0x0000000000401115 in main (argc=2, argv=0x7fff4959f598) at fc-list.c:157
>   157         fs = FcFontList (0, pat, os);
>   (gdb) printf "%p\n", pat
>   (nil)
>   (gdb) printf "%d: %s\n", argc, argv[1]
>   2: :charset=263A
>
> Now fc-list has the same invalid-pattern handling that fc-match.c has
> used since ae2aafe (Fix double free (spotted by Coverity, CID #1965),
> 2006-04-10) and fc-pattern has used since it's creation in ba7b50a
> (Add fc-pattern cmdline tool, 2010-04-20).
>
> After this commit, all FcNameParse calls in the utility programs are
> checked for invalid patterns, and the FcPatternCreate calls that
> happen when no pattern is given are checked for malloc errors.
> ---
>  fc-list/fc-list.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/fc-list/fc-list.c b/fc-list/fc-list.c
> index 5ad1333..4593260 100644
> --- a/fc-list/fc-list.c
> +++ b/fc-list/fc-list.c
> @@ -148,6 +148,10 @@ main (int argc, char **argv)
>      }
>      else
>         pat = FcPatternCreate ();
> +
> +    if (!pat)
> +       return 1;
> +
>      if (quiet && !os)
>         os = FcObjectSetCreate ();
>      if (!verbose && !format && !os)
> @@ -157,8 +161,7 @@ main (int argc, char **argv)
>      fs = FcFontList (0, pat, os);
>      if (os)
>         FcObjectSetDestroy (os);
> -    if (pat)
> -       FcPatternDestroy (pat);
> +    FcPatternDestroy (pat);
>
>      if (!quiet && fs)
>      {
> --
> 1.8.1.5
>
> _______________________________________________
> Fontconfig mailing list
> Fontconfig at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/fontconfig



-- 
Akira TAGOH


More information about the Fontconfig mailing list