Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com To: Cygwin Mailing List Subject: strchr bug? From: Vadim Egorov Date: 09 Nov 1999 15:36:24 +0300 Message-ID: Lines: 40 User-Agent: Gnus/5.070096 (Pterodactyl Gnus v0.96) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 #include 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