public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "konstantin.s.serebryany at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/18036] New: buffer overflow (read past end of buffer) in internal_fnmatch=>end_pattern with "**(!()" pattern
Date: Thu, 26 Feb 2015 18:12:00 -0000	[thread overview]
Message-ID: <bug-18036-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=18036

            Bug ID: 18036
           Summary: buffer overflow (read past end of buffer) in
                    internal_fnmatch=>end_pattern with "**(!()" pattern
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: konstantin.s.serebryany at gmail dot com
                CC: drepper.fsp at gmail dot com
             Flags: security+

Similar to https://sourceware.org/bugzilla/show_bug.cgi?id=18032
but in a different place: 

#include <fnmatch.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <assert.h>
int main(int argc, const char* argv[]) {
  long page_size = sysconf (_SC_PAGESIZE);
  assert(page_size > 0);
  char *page = mmap (NULL, 2 * page_size, PROT_READ | PROT_WRITE,
                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  assert(page != MAP_FAILED);
  assert(!mprotect (page + page_size, page_size, PROT_NONE));
  memset (page, ' ', page_size);
  const char p[] = "**(!()";
  strcpy(page, p); 
  fnmatch(page, p, FNM_EXTMATCH);
} 


gcc fn3.c && ./a.out 
Segmentation fault (core dumped)


gdb: 
(gdb) bt
#0  0x00007ffff7adaf4b in end_pattern (pattern=pattern@entry=0x7ffff7ff6002
"(!()") at fnmatch_loop.c:1032
#1  0x00007ffff7adcbb9 in internal_fnmatch (pattern=<optimized out>,
string=string@entry=0x7fffffffdcd0 "**(!()", string_end=0x7fffffffdcd6 "",
no_leading_period=no_leading_period@entry=0, 
    flags=flags@entry=32, ends=ends@entry=0x0, alloca_used=alloca_used@entry=0)
at fnmatch_loop.c:128
#2  0x00007ffff7addf72 in __fnmatch (pattern=0x7ffff7ff6000 "**(!()",
string=0x7fffffffdcd0 "**(!()", flags=32) at fnmatch.c:458
#3  0x000000000040084a in main ()

Reproduces on 2.19 and fresh trunk. Marking as security+ similar to bug 18032
Since bug 18032 has been fixed promptly I assume you don't mind these reports.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


             reply	other threads:[~2015-02-26 18:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-26 18:12 konstantin.s.serebryany at gmail dot com [this message]
2015-02-26 18:22 ` [Bug libc/18036] " ppluzhnikov at google dot com
2015-02-28  5:07 ` ppluzhnikov at google dot com
2015-03-02 21:37 ` cvs-commit at gcc dot gnu.org
2015-03-02 21:38 ` ppluzhnikov at google dot com
2023-06-06 12:24 ` helmut at subdivi dot de
2023-06-25 20:38 ` carnil at debian dot org
2023-06-25 20:38 ` carnil at debian dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-18036-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).