<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "http://sourceware.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="4.4+"
          urlbase="http://sourceware.org/bugzilla/"
          
          maintainer="overseers@sourceware.org"
>

    <bug>
          <bug_id>11883</bug_id>
          
          <creation_ts>2010-08-05 05:04:00 +0000</creation_ts>
          <short_desc>fnmatch() alloca() abuse, with security consequence</short_desc>
          <delta_ts>2010-08-10 04:27:18 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>glibc</product>
          <component>libc</component>
          <version>2.9</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Chris Evans">scarybeasts</reporter>
          <assigned_to name="Ulrich Drepper">drepper.fsp</assigned_to>
          <cc>glibc-bugs</cc>
          <cf_gcchost></cf_gcchost>
          <cf_gcctarget></cf_gcctarget>
          <cf_gccbuild></cf_gccbuild>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>44417</commentid>
    <comment_count>0</comment_count>
    <who name="Chris Evans">scarybeasts</who>
    <bug_when>2010-08-05 05:04:39 +0000</bug_when>
    <thetext>Demo:

#include &lt;err.h&gt;
#include &lt;fnmatch.h&gt;
#include &lt;locale.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

int main(int argc, const char* argv[]) {
  size_t num_as;
  char* p;
  setlocale(LC_ALL, &quot;en_US.UTF8&quot;);
  if (argc &lt; 2) {
    errx(1, &quot;Missing argument.&quot;);
  }
  num_as = atoi(argv[1]);
  if (num_as &lt; 5) {
    errx(1, &quot;Need 5.&quot;);
  }
  p = malloc(num_as);
  if (!p) {
    errx(1, &quot;malloc() failed.&quot;);
  }
  memset(p, &apos;A&apos;, num_as);
  p[num_as - 1] = &apos;\0&apos;;
  p[0] = &apos;f&apos;;
  p[1] = &apos;o&apos;;
  p[2] = &apos;o&apos;;
  p[3] = &apos;.&apos;;
  fnmatch(&quot;*.anim[1-9j]&quot;, p, 0);
  return 0;
}

./a.out 3000000
Segmentation fault

(If your default max stack size is greater than the default 8MB then you may 
need a larger number)

I chatted to some people and they suggested that there&apos;s probably a missing 
__libc_use_alloca() somewhere.

This was the source of a nasty Chromium bug which was worked around for now.

[Random aside: I can&apos;t seem to find the default value for __libc_alloca_cutoff 
but if it is &gt; PAGE_SIZE then that in of itself would cause serious issues since 
most people don&apos;t compile glibc with -fstack-check, combined with the fact that 
pthread stacks by default are separated with a single guard page]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>44498</commentid>
    <comment_count>1</comment_count>
    <who name="Ulrich Drepper">drepper.fsp</who>
    <bug_when>2010-08-10 04:27:18 +0000</bug_when>
    <thetext>I cannot reproduce any problem.  I did check in changes to keep the alloca use
limited.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>