From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id A6C042F09D for ; Mon, 26 Mar 2001 15:13:38 -0500 (EST) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id f2QKFCG23123 for axp-list@listman.redhat.com; Mon, 26 Mar 2001 15:15:12 -0500 Received: from fuggles.cam.nist.gov (fuggles.cam.nist.gov [129.6.88.69]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id f2QKFBV23112 for ; Mon, 26 Mar 2001 15:15:11 -0500 Received: (from donahue@localhost) by fuggles.cam.nist.gov (8.9.3/8.9.3) id PAA05587; Mon, 26 Mar 2001 15:13:26 -0500 X-Authentication-Warning: fuggles.cam.nist.gov: donahue set sender to michael.donahue@nist.gov using -f From: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15039.41702.809052.794191@fuggles.cam.nist.gov> Date: Mon, 26 Mar 2001 15:13:26 -0500 To: axp-list@redhat.com Subject: memchr bug? Request for enlightenment (lowercase 'e') X-Mailer: VM 6.92 under Emacs 20.7.1 X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com X-Reply-To: michael.donahue@nist.gov (Michael Donahue) List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: While doing some code testing with Electric Fence, I came across the following curiosity, on a stock RedHat 6.2/AXP system. Consider the short test program: #include #include #define TESTSTRING "12345678" int main() { char *p = (char *)malloc(strlen(TESTSTRING)+1); strcpy(p,TESTSTRING); memchr(p,'\0',79); free(p); return 0; } When I compile and run I get $ gcc memchr-test.c -lefence $ ./a.out Electric Fence 2.0.5 Copyright (C) 1987-1998 Bruce Perens. Segmentation fault It appears that memchr is reading memory past the end of the malloc'ed region. I don't know if this is actually a problem or not, but I don't see this behavior on Linux/x86 or Solaris. Incidentally, I can replace '\0' above with '5', '6', '7' or '8' with the same results. OTOH, '4' is okay, and I see no segfault with strlen(). So, is this a bug? Has it been fixed in newer libc? BTW, the *printf family uses memchr in its %.ns conversions, e.g., the following code exhibits the same behavior: #include #include #include #define TESTSTRING "12345678" int main() { char *p = (char *)malloc(strlen(TESTSTRING)+1); strcpy(p,TESTSTRING); printf("%.79s\n",p); free(p); return 0; } -m -- Michael J. Donahue National Institute of Standards and Technology Mathematical & Computational Sciences Division 100 Bureau Dr Stop 8910 Gaithersburg, MD 20899-8910 email: michael.donahue@nist.gov voice: (301) 975-5424 fax: (301) 990-4127 web: http://math.nist.gov/~MDonahue/