delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/11/09/07:38:21

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
To: Cygwin Mailing List <cygwin AT sourceware DOT cygnus DOT com>
Subject: strchr bug?
From: Vadim Egorov <egorovv AT 1c DOT ru>
Date: 09 Nov 1999 15:36:24 +0300
Message-ID: <upuxjq1tj.fsf@1c.ru>
Lines: 40
User-Agent: Gnus/5.070096 (Pterodactyl Gnus v0.96) Emacs/20.4
MIME-Version: 1.0
X-MDaemon-Deliver-To: cygwin AT sourceware DOT cygnus DOT com
X-Return-Path: EgorovV AT 1c DOT ru

Hello,
While porting ElectricFence to cygwin I encountered a problem
with strchr implementation in newlib.
When it finds character occurance near the end of string it seems 
to access (sometimes) memory past the end of string. When the memory
just after the end of string is unaccessible it causes access violation.
This can be reproduced by the following program:

-------------- test.cc --------------
#include <string.h>
#include <windows.h>
char pattern[] = "::\0";

int main()
{
    DWORD dw;
    int len = 4;
    if (sizeof(pattern) != len)
        return 1;
    char* base = (char*)VirtualAlloc(0, 0x10000, MEM_COMMIT, PAGE_READWRITE);
    char* end = base + 4096;
    if (!VirtualProtect(end, 4096, PAGE_NOACCESS, &dw))
        return 1;
    char* p = end - len;
    memcpy(p, pattern, len);
    p++;
    p = strchr(p, ':');
    return 0;
}
-------------- test.cc --------------

What confuses is that it happens only when optimization is turned on:
gcc test.cc -O2 -o test
I tried it with gcc 2.95 and 2.95.2 and recent cygwin snapshots.
Any idea?

-- 
Regards,
Vadim Egorov 



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019