Skip to contentSkip to conversation

glibc 2.3.1: fix for the i386 inline strings code

PATCH Applied Denis Zaitsev 3 participants 5 messages Jan 6, 2003 – Jan 14, 2003 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Nobody has answered to me for a while, so I'm resending this politely...

This is a trivial patch for the inlined i386 strings' header. Without it, say, X11 can't be compiled with -D__USE_STRING_INLINES - a problems will be caused by XtNewString and X11's own bzero. These problems are cured by the first and the second chunks of the patch, correspondingly.

So, please, apply this.

i386/i486/bits/string.h renamed from i386/i486/bits/string.h.orig +4 -4
@@ -40,10 +40,10 @@
 
 /* The macros are used in some of the optimized implementations below.  */
 #define __STRING_SMALL_GET16(src, idx) \
-  (((src)[idx + 1] << 8) | (src)[idx])
+  ((((char*)(src))[idx + 1] << 8) | ((char*)(src))[idx])
 #define __STRING_SMALL_GET32(src, idx) \
-  ((((src)[idx + 3] << 8 | (src)[idx + 2]) << 8				      \
-    | (src)[idx + 1]) << 8 | (src)[idx])
+  (((((char*)(src))[idx + 3] << 8 | ((char*)(src))[idx + 2]) << 8	      \
+    | ((char*)(src))[idx + 1]) << 8 | ((char*)(src))[idx])
 
 
 /* Copy N bytes of SRC to DEST.  */
@@ -229,7 +229,7 @@ memcmp (__const void *__s1, __const void
 	assignments using immediate operands.  But this uses to much	      \
 	memory (7, instead of 4 bytes).  So we force the value in a	      \
 	registers.  */							      \
-     if (n == 3 || n >= 5)						      \
+     if ((n) == 3 || (n) >= 5)						      \
        __asm__ __volatile__ ("" : "=r" (__c) : "0" (__c));		      \
 									      \
      /* This `switch' statement will be removed at compile-time.  */	      \

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 5 lines · Andreas Jaeger
Quoted 3 lines · Denis Zaitsev

Nobody has answered to me for a while, so I'm resending this politely...

Quoted 8 lines
Quoted 3 lines

This is a trivial patch for the inlined i386 strings' header. Without it, say, X11 can't be compiled with -D__USE_STRING_INLINES - a problems will be caused by XtNewString and X11's own bzero. These

What exactly is the problem with X11?

Andreas

The exact problem with XtNewString is that we have the "void pointer dereference" error when it is used with void* argument: XtNewString is a macros which uses strcpy, whose inline variant, in turn, uses __STRING_SMALL_GET(16|32), which don't cast their (str) argument to (char*). The patch inserts such a casting. But this is not the X-specific problem, I just met it when was compiling X. It's a general error - string functions should work happily with void* arguments, so __STRING_SMALL_GET macros' must not assume their (str) argument can't be of type void*...

Again, the second problem is not X-specific, but X-exposed (for me). X's bzero is defined as memset, and when we have something like

        bzero(..., col = screen->max_col + 1)

the inlined memset, which is a macros, dies, because there is no brackets around the second bzero's argument, where it is used in the macros. And, again, it is a general error - the brackets must be there. The second chunk of the patch cures this.

#3 lore raw

On Tue, Jan 07, 2003 at 08:43:01AM +0500, Denis Zaitsev wrote:
[...]

Quoted 9 lines

The exact problem with XtNewString is that we have the "void pointer dereference" error when it is used with void* argument: XtNewString is a macros which uses strcpy, whose inline variant, in turn, uses __STRING_SMALL_GET(16|32), which don't cast their (str) argument to (char*). The patch inserts such a casting. But this is not the X-specific problem, I just met it when was compiling X. It's a general error - string functions should work happily with void* arguments, so __STRING_SMALL_GET macros' must not assume their (str) argument can't be of type void*...

To be more specific: __STRING_SMALL_GET expects the (str) argument to be an `unsigned char *'. Everything else will make it do funny things when (signed) characters have values >= 128. Since __strcpy_a_small() and __stpcpy_a_small() pass the pointer unmodified, they're broken as well.

Signature · 2 lines
 Michael "Tired" Riepe <[email protected]>
 "All I wanna do is have a little fun before I die"
#4 lore raw
Quoted 12 lines · Michael Riepe

On Tue, Jan 07, 2003 at 08:43:01AM +0500, Denis Zaitsev wrote:
[...]

Quoted 9 lines

The exact problem with XtNewString is that we have the "void pointer dereference" error when it is used with void* argument: XtNewString is a macros which uses strcpy, whose inline variant, in turn, uses __STRING_SMALL_GET(16|32), which don't cast their (str) argument to (char*). The patch inserts such a casting. But this is not the X-specific problem, I just met it when was compiling X. It's a general error - string functions should work happily with void* arguments, so __STRING_SMALL_GET macros' must not assume their (str) argument can't be of type void*...

Quoted 5 lines

To be more specific: __STRING_SMALL_GET expects the (str) argument to be an `unsigned char *'. Everything else will make it do funny things when (signed) characters have values >= 128. Since __strcpy_a_small() and __stpcpy_a_small() pass the pointer unmodified, they're broken as well.

You are right, indeed... There must be the (unsigned char*) cast.

#5 lore raw
In reply to Denis Zaitsev

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

Quoted 5 lines · Denis Zaitsev

This is a trivial patch for the inlined i386 strings' header. Without it, say, X11 can't be compiled with -D__USE_STRING_INLINES - a problems will be caused by XtNewString and X11's own bzero. These problems are cured by the first and the second chunks of the patch, correspondingly.

I've applied the patch after correcting the type used in the casts. Thanks,

- --
- --------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat --' drepper at redhat.com ---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+I7Gd2ijCOnn/RHQRAsVBAJ956F4GTF/fv1RpbU9nImKsPvgfxwCghrPN UWiP7thvgVDX78LkRQleBks=
=V2JO
-----END PGP SIGNATURE-----