bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: required memchr behavior


From: Eric Blake
Subject: Re: required memchr behavior
Date: Mon, 08 Jun 2009 06:36:47 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Bruno Haible on 5/31/2009 7:08 AM:
>> But as there are systems in the wild with the broken implementation, we
>> should probably start worrying about replacing the buggy memchr
>> implementations.
> 
> As a first step, let me add a test to test-memchr. Let's see whether we
> get some reports about it. - Probably we also should undeprecate 'memchr',
> so that its unit test gets included into m4, gettext, coreutils, etc.?

Yes; I've done that as follows, and also added memchr as a dependency for
vasnprintf (the only module that used memchr but did not depend on it).

>       * tests/test-strstr.c (main): Update comment.

We need to also touch up this test to use the memory fence, otherwise we
won't see strstr failures without the use of efence or other malloc
debugger.  Done as follows.  I'm not sure if it is worth trying to also
use a memory fence for a *printf test of %.*s, so I'll leave that to you
if you'd like to start checking for it.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkotBd8ACgkQ84KuGfSFAYDogACfQDwZXUmSkO/gKUseoxYZVn69
I6sAnA8VvhuFh8jL2S8vC9h0ZZfW9IUc
=ImXk
-----END PGP SIGNATURE-----
>From 83d94e5cd55ac5bad3b53eaf5547ff0e4c296346 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 8 Jun 2009 06:11:16 -0600
Subject: [PATCH 1/2] memchr: no longer obsolete, for wider field testing

* modules/memchr (Status, Notice): Delete, this module is no
longer obsolete.
* modules/vasnprintf (Depends-on): Add memchr.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog          |   11 +++++++++--
 modules/memchr     |    7 -------
 modules/vasnprintf |    2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a198937..541efa7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-06-08  Eric Blake  <address@hidden>
+
+       memchr: no longer obsolete, for wider field testing
+       * modules/memchr (Status, Notice): Delete, this module is no
+       longer obsolete.
+       * modules/vasnprintf (Depends-on): Add memchr.
+
 2009-06-07  Jim Meyering  <address@hidden>

        hash: declare some functions with the warn_unused_result attribute
diff --git a/modules/memchr b/modules/memchr
index 1ec8f41..da7e7a2 100644
--- a/modules/memchr
+++ b/modules/memchr
@@ -1,12 +1,6 @@
 Description:
 memchr() function: scan memory for a byte.

-Status:
-obsolete
-
-Notice:
-This module is obsolete.
-
 Files:
 lib/memchr.c
 m4/memchr.m4
@@ -26,4 +20,3 @@ LGPLv2+

 Maintainer:
 Jim Meyering, glibc
-
diff --git a/modules/vasnprintf b/modules/vasnprintf
index 4617e3e..819495c 100644
--- a/modules/vasnprintf
+++ b/modules/vasnprintf
@@ -24,6 +24,7 @@ float
 stdint
 xsize
 errno
+memchr

 configure.ac:
 gl_FUNC_VASNPRINTF
@@ -38,4 +39,3 @@ LGPLv2+

 Maintainer:
 Bruno Haible
-
-- 
1.6.3.rc3.2.g4b51


>From 3cbc841063fdad8a63d7fa9b247026f44fddab00 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 8 Jun 2009 06:17:39 -0600
Subject: [PATCH 2/2] test-strstr: use memory fence, when possible

* tests/test-strstr.c (main): Use memory fence, in order to be
more likely to trigger Debian bug 521737.
* modules/strstr-tests (Files): Pull in additional files.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog            |    5 +++++
 modules/strstr-tests |    8 +++++++-
 tests/test-strstr.c  |    9 +++++++--
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 541efa7..92de5bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-06-08  Eric Blake  <address@hidden>

+       test-strstr: use memory fence, when possible
+       * tests/test-strstr.c (main): Use memory fence, in order to be
+       more likely to trigger Debian bug 521737.
+       * modules/strstr-tests (Files): Pull in additional files.
+
        memchr: no longer obsolete, for wider field testing
        * modules/memchr (Status, Notice): Delete, this module is no
        longer obsolete.
diff --git a/modules/strstr-tests b/modules/strstr-tests
index 23e67b0..8f09e58 100644
--- a/modules/strstr-tests
+++ b/modules/strstr-tests
@@ -1,12 +1,18 @@
 Files:
 tests/test-strstr.c
+tests/zerosize-ptr.h
+m4/mmap-anon.m4

 Depends-on:
+extensions
+getpagesize

 configure.ac:
 AC_CHECK_DECLS_ONCE([alarm])
+gl_FUNC_MMAP_ANON
+AC_CHECK_HEADERS_ONCE([sys/mman.h])
+AC_CHECK_FUNCS_ONCE([mprotect])

 Makefile.am:
 TESTS += test-strstr
 check_PROGRAMS += test-strstr
-
diff --git a/tests/test-strstr.c b/tests/test-strstr.c
index f7bc4cb..37f4bac 100644
--- a/tests/test-strstr.c
+++ b/tests/test-strstr.c
@@ -24,6 +24,8 @@
 #include <stdlib.h>
 #include <unistd.h>

+#include "zerosize-ptr.h"
+
 #define ASSERT(expr) \
   do                                                                        \
     {                                                                       \
@@ -68,13 +70,16 @@ main (int argc, char *argv[])
        This is a bug in memchr(), see the Austin Group's clarification
        <http://www.opengroup.org/austin/docs/austin_454.txt>.  */
     const char *fix = "aBaaaaaaaaaaax";
-    char *input = malloc (strlen (fix) + 1);
+    char *page_boundary = (char *) zerosize_ptr ();
+    size_t len = strlen (fix) + 1;
+    char *input = page_boundary ? page_boundary - len : malloc (len);
     const char *result;

     strcpy (input, fix);
     result = strstr (input, "B1x");
     ASSERT (result == NULL);
-    free (input);
+    if (!page_boundary)
+      free (input);
   }

   {
-- 
1.6.3.rc3.2.g4b51


reply via email to

[Prev in Thread] Current Thread [Next in Thread]