# --- SDE-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # Filename: package/.../glibc/glibc-2.16.0-0000-upstream-fixes.patch # Copyright (C) 2013 The OpenSDE Project # # More information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any later # version. # --- SDE-COPYRIGHT-NOTE-END --- From 33c9f2211ca7b23299e016ee246e2d2c6cc6e831 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 3 Jul 2012 15:22:05 -0400 Subject: [PATCH] sunrpc: fix rpc bootstrap builds If you build & install glibc w/rpc disabled, you no longer have headers in /usr/include/rpc/ (this is expected). But if you try to build glibc w/rpc enabled, this gets into a bad state due to the new rpc helpers that get cross-compiled: $ make ... x86_64-pc-linux-gnu-gcc -m32 -D_RPC_THREAD_SAFE_ -D_GNU_SOURCE -DIS_IN_build \ -include $objdir/config.h rpc_clntout.c -o $objdir/sunrpc/cross-rpc_clntout.o \ -MMD -MP -MF $objdir/sunrpc/cross-rpc_clntout.o.dt -MT $objdir/sunrpc/cross-rpc_clntout.o -c rpc_clntout.c:34:23: fatal error: rpc/types.h: No such file or directory compilation terminated. make: *** [$objdir/sunrpc/cross-rpc_clntout.o] Error 1 Signed-off-by: Mike Frysinger (cherry picked from commit fb21f89b75d0152aa42efb6b620843799a4cd76b) --- sunrpc/rpc_clntout.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/sunrpc/rpc_clntout.c b/sunrpc/rpc_clntout.c index ec040c7..ce4d2a4 100644 --- a/sunrpc/rpc_clntout.c +++ b/sunrpc/rpc_clntout.c @@ -31,7 +31,7 @@ */ #include #include -#include +#include "rpc/types.h" #include "rpc_parse.h" #include "rpc_util.h" #include "proto.h" -- 1.7.2.3 From 76adf226534522267a38cf4b7d293706279d5cd2 Mon Sep 17 00:00:00 2001 From: Liubov Dmitrieva Date: Wed, 15 Aug 2012 21:06:55 +0200 Subject: [PATCH] Fix segmentation fault in strncasecmp for i686 2012-08-15 Liubov Dmitrieva [BZ #14195] * sysdeps/i386/i686/multiarch/strcmp-sssse3.S: Fix segmentation fault for a case of two empty input strings. * string/test-strncasecmp.c (check1): Renamed to... (bz12205): ...this. (bz14195): Add new testcase for two empty input strings and N > 0. (test_main): Call new testcase, adapt for renamed function. (cherry picked from commit b3f479a85a3e191befbe821d787d7f71c0f64e79) --- string/test-strncasecmp.c | 18 ++++++++++++++---- sysdeps/i386/i686/multiarch/strcmp-ssse3.S | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 6c17530..acfe668 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -1,5 +1,5 @@ /* Test and measure strncasecmp functions. - Copyright (C) 1999, 2002, 2003, 2005, 2010 Free Software Foundation, Inc. + Copyright (C) 1999-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Jakub Jelinek , 1999. @@ -251,9 +251,9 @@ do_random_tests (void) } } - +/* Regression test for BZ #12205 */ static void -check1 (void) +bz12205 (void) { static char cp [4096+16] __attribute__ ((aligned(4096))); static char gotrel[4096] __attribute__ ((aligned(4096))); @@ -270,6 +270,15 @@ check1 (void) check_result (impl, s1, s2, n, exp_result); } +/* Regression test for BZ #14195 */ +static void +bz14195 (void) +{ + const char *empty_string = ""; + FOR_EACH_IMPL (impl, 0) + check_result (impl, empty_string, "", 5, 0); +} + int test_main (void) { @@ -277,7 +286,8 @@ test_main (void) test_init (); - check1 (); + bz12205 (); + bz14195 (); printf ("%23s", ""); FOR_EACH_IMPL (impl, 0) diff --git a/sysdeps/i386/i686/multiarch/strcmp-ssse3.S b/sysdeps/i386/i686/multiarch/strcmp-ssse3.S index 5e6321e..9735ad0 100644 --- a/sysdeps/i386/i686/multiarch/strcmp-ssse3.S +++ b/sysdeps/i386/i686/multiarch/strcmp-ssse3.S @@ -2445,7 +2445,7 @@ L(less16bytes_sncmp): # endif jne L(neq_sncmp) test %cl, %cl - je L(eq) + je L(eq_sncmp) cmp $1, REM je L(eq_sncmp) -- 1.7.2.3 From a01a14d518c2b32cdb0d21942b2d34da33692409 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Mon, 27 Aug 2012 15:59:24 +0000 Subject: [PATCH] Fix strtod integer/buffer overflow (bug 14459). (cherry picked from commit d6e70f4368533224e66d10b7f2126b899a3fd5e4) --- stdlib/Makefile | 3 +- stdlib/strtod_l.c | 142 ++++++++++++++++++++++++++++++++--------- stdlib/tst-strtod-overflow.c | 48 ++++++++++++++ 3 files changed, 161 insertions(+), 32 deletions(-) create mode 100644 stdlib/tst-strtod-overflow.c diff --git a/stdlib/Makefile b/stdlib/Makefile index f7811c5..79c9acb 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -68,7 +68,8 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \ tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \ tst-makecontext tst-strtod4 tst-strtod5 tst-qsort2 \ tst-makecontext2 tst-strtod6 tst-unsetenv1 \ - tst-makecontext3 bug-getcontext bug-fmtmsg1 + tst-makecontext3 bug-getcontext bug-fmtmsg1 \ + tst-strtod-overflow include ../Makeconfig diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c index 2166a08..a8a7ea8 100644 --- a/stdlib/strtod_l.c +++ b/stdlib/strtod_l.c @@ -60,6 +60,7 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **, #include #include #include +#include /* The gmp headers need some configuration frobs. */ #define HAVE_ALLOCA 1 @@ -72,7 +73,6 @@ extern unsigned long long int ____strtoull_l_internal (const char *, char **, #include "longlong.h" #include "fpioconst.h" -#define NDEBUG 1 #include @@ -174,19 +174,19 @@ extern const mp_limb_t _tens_in_limb[MAX_DIG_PER_LIMB + 1]; /* Return a floating point number of the needed type according to the given multi-precision number after possible rounding. */ static FLOAT -round_and_return (mp_limb_t *retval, int exponent, int negative, +round_and_return (mp_limb_t *retval, intmax_t exponent, int negative, mp_limb_t round_limb, mp_size_t round_bit, int more_bits) { if (exponent < MIN_EXP - 1) { - mp_size_t shift = MIN_EXP - 1 - exponent; - - if (shift > MANT_DIG) + if (exponent < MIN_EXP - 1 - MANT_DIG) { __set_errno (ERANGE); return 0.0; } + mp_size_t shift = MIN_EXP - 1 - exponent; + more_bits |= (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0; if (shift == MANT_DIG) /* This is a special case to handle the very seldom case where @@ -233,6 +233,9 @@ round_and_return (mp_limb_t *retval, int exponent, int negative, __set_errno (ERANGE); } + if (exponent > MAX_EXP) + goto overflow; + if ((round_limb & (((mp_limb_t) 1) << round_bit)) != 0 && (more_bits || (retval[0] & 1) != 0 || (round_limb & ((((mp_limb_t) 1) << round_bit) - 1)) != 0)) @@ -258,6 +261,7 @@ round_and_return (mp_limb_t *retval, int exponent, int negative, } if (exponent > MAX_EXP) + overflow: return negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL; return MPN2FLOAT (retval, exponent, negative); @@ -271,7 +275,7 @@ round_and_return (mp_limb_t *retval, int exponent, int negative, factor for the resulting number (see code) multiply by it. */ static const STRING_TYPE * str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize, - int *exponent + intmax_t *exponent #ifndef USE_WIDE_CHAR , const char *decimal, size_t decimal_len, const char *thousands #endif @@ -301,6 +305,7 @@ str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize, cy += __mpn_add_1 (n, n, *nsize, low); if (cy != 0) { + assert (*nsize < MPNSIZE); n[*nsize] = cy; ++(*nsize); } @@ -335,7 +340,7 @@ str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize, } while (--digcnt > 0); - if (*exponent > 0 && cnt + *exponent <= MAX_DIG_PER_LIMB) + if (*exponent > 0 && *exponent <= MAX_DIG_PER_LIMB - cnt) { low *= _tens_in_limb[*exponent]; start = _tens_in_limb[cnt + *exponent]; @@ -355,7 +360,10 @@ str_to_mpn (const STRING_TYPE *str, int digcnt, mp_limb_t *n, mp_size_t *nsize, cy = __mpn_mul_1 (n, n, *nsize, start); cy += __mpn_add_1 (n, n, *nsize, low); if (cy != 0) - n[(*nsize)++] = cy; + { + assert (*nsize < MPNSIZE); + n[(*nsize)++] = cy; + } } return str; @@ -413,7 +421,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) { int negative; /* The sign of the number. */ MPN_VAR (num); /* MP representation of the number. */ - int exponent; /* Exponent of the number. */ + intmax_t exponent; /* Exponent of the number. */ /* Numbers starting `0X' or `0x' have to be processed with base 16. */ int base = 10; @@ -435,7 +443,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) /* Points at the character following the integer and fractional digits. */ const STRING_TYPE *expp; /* Total number of digit and number of digits in integer part. */ - int dig_no, int_no, lead_zero; + size_t dig_no, int_no, lead_zero; /* Contains the last character read. */ CHAR_TYPE c; @@ -767,7 +775,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) are all or any is really a fractional digit will be decided later. */ int_no = dig_no; - lead_zero = int_no == 0 ? -1 : 0; + lead_zero = int_no == 0 ? (size_t) -1 : 0; /* Read the fractional digits. A special case are the 'american style' numbers like `16.' i.e. with decimal point but without @@ -789,12 +797,13 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) (base == 16 && ({ CHAR_TYPE lo = TOLOWER (c); lo >= L_('a') && lo <= L_('f'); }))) { - if (c != L_('0') && lead_zero == -1) + if (c != L_('0') && lead_zero == (size_t) -1) lead_zero = dig_no - int_no; ++dig_no; c = *++cp; } } + assert (dig_no <= (uintmax_t) INTMAX_MAX); /* Remember start of exponent (if any). */ expp = cp; @@ -817,24 +826,80 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) if (c >= L_('0') && c <= L_('9')) { - int exp_limit; + intmax_t exp_limit; /* Get the exponent limit. */ if (base == 16) - exp_limit = (exp_negative ? - -MIN_EXP + MANT_DIG + 4 * int_no : - MAX_EXP - 4 * int_no + 4 * lead_zero + 3); + { + if (exp_negative) + { + assert (int_no <= (uintmax_t) (INTMAX_MAX + + MIN_EXP - MANT_DIG) / 4); + exp_limit = -MIN_EXP + MANT_DIG + 4 * (intmax_t) int_no; + } + else + { + if (int_no) + { + assert (lead_zero == 0 + && int_no <= (uintmax_t) INTMAX_MAX / 4); + exp_limit = MAX_EXP - 4 * (intmax_t) int_no + 3; + } + else if (lead_zero == (size_t) -1) + { + /* The number is zero and this limit is + arbitrary. */ + exp_limit = MAX_EXP + 3; + } + else + { + assert (lead_zero + <= (uintmax_t) (INTMAX_MAX - MAX_EXP - 3) / 4); + exp_limit = (MAX_EXP + + 4 * (intmax_t) lead_zero + + 3); + } + } + } else - exp_limit = (exp_negative ? - -MIN_10_EXP + MANT_DIG + int_no : - MAX_10_EXP - int_no + lead_zero + 1); + { + if (exp_negative) + { + assert (int_no + <= (uintmax_t) (INTMAX_MAX + MIN_10_EXP - MANT_DIG)); + exp_limit = -MIN_10_EXP + MANT_DIG + (intmax_t) int_no; + } + else + { + if (int_no) + { + assert (lead_zero == 0 + && int_no <= (uintmax_t) INTMAX_MAX); + exp_limit = MAX_10_EXP - (intmax_t) int_no + 1; + } + else if (lead_zero == (size_t) -1) + { + /* The number is zero and this limit is + arbitrary. */ + exp_limit = MAX_10_EXP + 1; + } + else + { + assert (lead_zero + <= (uintmax_t) (INTMAX_MAX - MAX_10_EXP - 1)); + exp_limit = MAX_10_EXP + (intmax_t) lead_zero + 1; + } + } + } + + if (exp_limit < 0) + exp_limit = 0; do { - exponent *= 10; - exponent += c - L_('0'); - - if (__builtin_expect (exponent > exp_limit, 0)) + if (__builtin_expect ((exponent > exp_limit / 10 + || (exponent == exp_limit / 10 + && c - L_('0') > exp_limit % 10)), 0)) /* The exponent is too large/small to represent a valid number. */ { @@ -843,7 +908,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) /* We have to take care for special situation: a joker might have written "0.0e100000" which is in fact zero. */ - if (lead_zero == -1) + if (lead_zero == (size_t) -1) result = negative ? -0.0 : 0.0; else { @@ -862,6 +927,9 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) /* NOTREACHED */ } + exponent *= 10; + exponent += c - L_('0'); + c = *++cp; } while (c >= L_('0') && c <= L_('9')); @@ -930,7 +998,14 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) } #endif startp += lead_zero + decimal_len; - exponent -= base == 16 ? 4 * lead_zero : lead_zero; + assert (lead_zero <= (base == 16 + ? (uintmax_t) INTMAX_MAX / 4 + : (uintmax_t) INTMAX_MAX)); + assert (lead_zero <= (base == 16 + ? ((uintmax_t) exponent + - (uintmax_t) INTMAX_MIN) / 4 + : ((uintmax_t) exponent - (uintmax_t) INTMAX_MIN))); + exponent -= base == 16 ? 4 * (intmax_t) lead_zero : (intmax_t) lead_zero; dig_no -= lead_zero; } @@ -972,7 +1047,10 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) } /* Adjust the exponent for the bits we are shifting in. */ - exponent += bits - 1 + (int_no - 1) * 4; + assert (int_no <= (uintmax_t) (exponent < 0 + ? (INTMAX_MAX - bits + 1) / 4 + : (INTMAX_MAX - exponent - bits + 1) / 4)); + exponent += bits - 1 + ((intmax_t) int_no - 1) * 4; while (--dig_no > 0 && idx >= 0) { @@ -1024,13 +1102,15 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) really integer digits or belong to the fractional part; i.e. we normalize 123e-2 to 1.23. */ { - register int incr = (exponent < 0 ? MAX (-int_no, exponent) - : MIN (dig_no - int_no, exponent)); + register intmax_t incr = (exponent < 0 + ? MAX (-(intmax_t) int_no, exponent) + : MIN ((intmax_t) dig_no - (intmax_t) int_no, + exponent)); int_no += incr; exponent -= incr; } - if (__builtin_expect (int_no + exponent > MAX_10_EXP + 1, 0)) + if (__builtin_expect (exponent > MAX_10_EXP + 1 - (intmax_t) int_no, 0)) { __set_errno (ERANGE); return negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL; @@ -1215,7 +1295,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) digits we should have enough bits for the result. The remaining decimal digits give us the information that more bits are following. This can be used while rounding. (Two added as a safety margin.) */ - if (dig_no - int_no > (MANT_DIG - bits + 2) / 3 + 2) + if ((intmax_t) dig_no > (intmax_t) int_no + (MANT_DIG - bits + 2) / 3 + 2) { dig_no = int_no + (MANT_DIG - bits + 2) / 3 + 2; more_bits = 1; @@ -1223,7 +1303,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc) else more_bits = 0; - neg_exp = dig_no - int_no - exponent; + neg_exp = (intmax_t) dig_no - (intmax_t) int_no - exponent; /* Construct the denominator. */ densize = 0; diff --git a/stdlib/tst-strtod-overflow.c b/stdlib/tst-strtod-overflow.c new file mode 100644 index 0000000..668d55b --- /dev/null +++ b/stdlib/tst-strtod-overflow.c @@ -0,0 +1,48 @@ +/* Test for integer/buffer overflow in strtod. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#define EXPONENT "e-2147483649" +#define SIZE 214748364 + +static int +do_test (void) +{ + char *p = malloc (1 + SIZE + sizeof (EXPONENT)); + if (p == NULL) + { + puts ("malloc failed, cannot test for overflow"); + return 0; + } + p[0] = '1'; + memset (p + 1, '0', SIZE); + memcpy (p + 1 + SIZE, EXPONENT, sizeof (EXPONENT)); + double d = strtod (p, NULL); + if (d != 0) + { + printf ("strtod returned wrong value: %a\n", d); + return 1; + } + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- 1.7.2.3 From 39086d7f713d8e54f70362d662a161d783ccd5e6 Mon Sep 17 00:00:00 2001 From: H.J. Lu Date: Wed, 29 Aug 2012 06:45:37 -0700 Subject: [PATCH] Use LD_SO to set $ld_so_name/$ld_so_version cherry-pick d22e28b070d3d1572d39a463d711c6f223078552 --- Makefile | 2 +- scripts/test-installation.pl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletions(-) diff --git a/Makefile b/Makefile index 89588c1..f993c91 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,7 @@ install: ifneq (no,$(PERL)) ifeq (/usr,$(prefix)) ifeq (,$(install_root)) - CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx) + LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx) endif endif endif diff --git a/scripts/test-installation.pl b/scripts/test-installation.pl index 1b22086..0700770 100755 --- a/scripts/test-installation.pl +++ b/scripts/test-installation.pl @@ -25,6 +25,11 @@ if ($ENV{CC}) { } else { $CC= "gcc"; } +if ($ENV{LD_SO}) { + $LD_SO = $ENV{LD_SO}; +} else { + $LD_SO = ""; +} sub usage { print "Usage: test-installation [soversions.mk]\n"; @@ -112,6 +117,8 @@ while () { $link_libs .= " -l$name"; $versions{$name} = $version; } + } elsif ($LD_SO ne "") { + ($ld_so_name, $ld_so_version) = split ('\.so\.', $LD_SO); } else { if (/^ld\.so/) { ($ld_so_name, $ld_so_version)= /=(.*)\.so\.(.*)$/; -- 1.7.2.3 From ec0f78d65ce08fb4158cc31624c4872c0df9b545 Mon Sep 17 00:00:00 2001 From: H.J. Lu Date: Mon, 24 Sep 2012 08:58:04 -0700 Subject: [PATCH] Properly handle fencepost with MALLOC_ALIGN_MASK Cherry-pick commit ced6f16ee919d12725840d43d007f1cfd67118df. --- malloc/arena.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/malloc/arena.c b/malloc/arena.c index 33c4ff3..71a0dee 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -652,15 +652,19 @@ heap_trim(heap_info *heap, size_t pad) unsigned long pagesz = GLRO(dl_pagesize); mchunkptr top_chunk = top(ar_ptr), p, bck, fwd; heap_info *prev_heap; - long new_size, top_size, extra; + long new_size, top_size, extra, prev_size, misalign; /* Can this heap go away completely? */ while(top_chunk == chunk_at_offset(heap, sizeof(*heap))) { prev_heap = heap->prev; - p = chunk_at_offset(prev_heap, prev_heap->size - (MINSIZE-2*SIZE_SZ)); + prev_size = prev_heap->size - (MINSIZE-2*SIZE_SZ); + p = chunk_at_offset(prev_heap, prev_size); + /* fencepost must be properly aligned. */ + misalign = ((long) p) & MALLOC_ALIGN_MASK; + p = chunk_at_offset(prev_heap, prev_size - misalign); assert(p->size == (0|PREV_INUSE)); /* must be fencepost */ p = prev_chunk(p); - new_size = chunksize(p) + (MINSIZE-2*SIZE_SZ); + new_size = chunksize(p) + (MINSIZE-2*SIZE_SZ) + misalign; assert(new_size>0 && new_size<(long)(2*MINSIZE)); if(!prev_inuse(p)) new_size += p->prev_size; -- 1.7.2.3 From d22cf229673050abfdb3be5124bd58eb2fc2b965 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 25 Sep 2012 19:38:15 +0000 Subject: [PATCH] Use size_t instead of int for internal variables in glob (bug 14621). (cherry picked from commit b87c4b24d97321ef2f2da357f8fcf11f1f61e3dc) --- posix/glob.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/posix/glob.c b/posix/glob.c index 68ea205..87d4f1b 100644 --- a/posix/glob.c +++ b/posix/glob.c @@ -217,7 +217,7 @@ static int collated_compare (const void *, const void *) __THROW; static const char * next_brace_sub (const char *cp, int flags) { - unsigned int depth = 0; + size_t depth = 0; while (*cp != '\0') if ((flags & GLOB_NOESCAPE) == 0 && *cp == '\\') { @@ -960,7 +960,7 @@ glob (pattern, flags, errfunc, pglob) && S_ISDIR (st.st_mode)) : (__stat64 (dirname, &st64) == 0 && S_ISDIR (st64.st_mode))))) { - int newcount = pglob->gl_pathc + pglob->gl_offs; + size_t newcount = pglob->gl_pathc + pglob->gl_offs; char **new_gl_pathv; if (newcount > UINTPTR_MAX - (1 + 1) @@ -1059,7 +1059,7 @@ glob (pattern, flags, errfunc, pglob) appending the results to PGLOB. */ for (i = 0; i < dirs.gl_pathc; ++i) { - int old_pathc; + size_t old_pathc; #ifdef SHELL { @@ -1114,7 +1114,7 @@ glob (pattern, flags, errfunc, pglob) /* No matches. */ if (flags & GLOB_NOCHECK) { - int newcount = pglob->gl_pathc + pglob->gl_offs; + size_t newcount = pglob->gl_pathc + pglob->gl_offs; char **new_gl_pathv; if (newcount > UINTPTR_MAX - 2 @@ -1158,7 +1158,7 @@ glob (pattern, flags, errfunc, pglob) } else { - int old_pathc = pglob->gl_pathc; + size_t old_pathc = pglob->gl_pathc; int orig_flags = flags; if (meta & 2) -- 1.7.2.3 From 2a9afa3d1bd0aacf4df9106342d973e368e315d5 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Fri, 28 Sep 2012 12:48:42 -0600 Subject: [PATCH] Don't parse %s format argument as multibyte string (cherry picked from commit 715a900c9085907fa749589bf738b192b1a2bda5) 2012-09-28 Andreas Schwab [BZ #6530] * stdio-common/vfprintf.c (process_string_arg): Revert 2000-07-22 change. 2011-09-28 Jonathan Nieder * stdio-common/Makefile (tst-sprintf-ENV): Set environment for testcase. * stdio-common/tst-sprintf.c: Include (main): Test sprintf's handling of incomplete multibyte characters. --- stdio-common/Makefile | 1 + stdio-common/tst-sprintf.c | 13 +++++++++++++ stdio-common/vfprintf.c | 39 +++------------------------------------ 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/stdio-common/Makefile b/stdio-common/Makefile index a29924b..42e45dc 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -116,6 +116,7 @@ CFLAGS-scanf17.c = -I../libio -I../stdlib -I../wcsmbs -I../time -I../string \ # We know the test has a format string problem. CFLAGS-tst-sprintf.c = -Wno-format +tst-sprintf-ENV = LOCPATH=$(common-objpfx)localedata tst-sscanf-ENV = LOCPATH=$(common-objpfx)localedata tst-swprintf-ENV = LOCPATH=$(common-objpfx)localedata test-vfprintf-ENV = LOCPATH=$(common-objpfx)localedata diff --git a/stdio-common/tst-sprintf.c b/stdio-common/tst-sprintf.c index c04fef1..c4e911f 100644 --- a/stdio-common/tst-sprintf.c +++ b/stdio-common/tst-sprintf.c @@ -1,5 +1,6 @@ #include #include +#include #include @@ -58,5 +59,17 @@ main (void) result = 1; } + if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL) + { + puts ("cannot set locale"); + result = 1; + } + else if (sprintf (buf, "%.8s\n", "Foo: \277") != 7 + || strcmp (buf, "Foo: \277\n") != 0) + { + printf ("sprintf (buf, \"%%.8s\\n\", \"Foo: \\277\") produced '%s' output\n", buf); + result = 1; + } + return result; } diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c index d569034..17d3f42 100644 --- a/stdio-common/vfprintf.c +++ b/stdio-common/vfprintf.c @@ -1168,42 +1168,9 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap) else if (!is_long && spec != L_('S')) \ { \ if (prec != -1) \ - { \ - /* Search for the end of the string, but don't search past \ - the length (in bytes) specified by the precision. Also \ - don't use incomplete characters. */ \ - if (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX) == 1) \ - len = __strnlen (string, prec); \ - else \ - { \ - /* In case we have a multibyte character set the \ - situation is more complicated. We must not copy \ - bytes at the end which form an incomplete character. */\ - size_t ignore_size = (unsigned) prec > 1024 ? 1024 : prec;\ - wchar_t ignore[ignore_size]; \ - const char *str2 = string; \ - const char *strend = string + prec; \ - if (strend < string) \ - strend = (const char *) UINTPTR_MAX; \ - \ - mbstate_t ps; \ - memset (&ps, '\0', sizeof (ps)); \ - \ - while (str2 != NULL && str2 < strend) \ - if (__mbsnrtowcs (ignore, &str2, strend - str2, \ - ignore_size, &ps) == (size_t) -1) \ - { \ - /* Conversion function has set errno. */ \ - done = -1; \ - goto all_done; \ - } \ - \ - if (str2 == NULL) \ - len = strlen (string); \ - else \ - len = str2 - string - (ps.__count & 7); \ - } \ - } \ + /* Search for the end of the string, but don't search past \ + the length (in bytes) specified by the precision. */ \ + len = __strnlen (string, prec); \ else \ len = strlen (string); \ } \ -- 1.7.2.3 From 59fca14adeaebea87b8171e35ab41bb8e93008bf Mon Sep 17 00:00:00 2001 From: H.J. Lu Date: Tue, 2 Oct 2012 05:05:17 -0700 Subject: [PATCH] Define HAS_FMA with bit_FMA_Usable cherry-pick 0569936773c861c791f10bba5e2f4cac5fbb4e78 --- sysdeps/x86_64/multiarch/init-arch.c | 3 +++ sysdeps/x86_64/multiarch/init-arch.h | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sysdeps/x86_64/multiarch/init-arch.c b/sysdeps/x86_64/multiarch/init-arch.c index fb44dcf..fed5ab8 100644 --- a/sysdeps/x86_64/multiarch/init-arch.c +++ b/sysdeps/x86_64/multiarch/init-arch.c @@ -156,6 +156,9 @@ __init_cpu_features (void) /* Determine if AVX is usable. */ if (CPUID_AVX) __cpu_features.feature[index_AVX_Usable] |= bit_AVX_Usable; + /* Determine if FMA is usable. */ + if (CPUID_FMA) + __cpu_features.feature[index_FMA_Usable] |= bit_FMA_Usable; /* Determine if FMA4 is usable. */ if (CPUID_FMA4) __cpu_features.feature[index_FMA4_Usable] |= bit_FMA4_Usable; diff --git a/sysdeps/x86_64/multiarch/init-arch.h b/sysdeps/x86_64/multiarch/init-arch.h index 45e2651..f33f1c8 100644 --- a/sysdeps/x86_64/multiarch/init-arch.h +++ b/sysdeps/x86_64/multiarch/init-arch.h @@ -22,7 +22,8 @@ #define bit_Fast_Unaligned_Load (1 << 4) #define bit_Prefer_PMINUB_for_stringop (1 << 5) #define bit_AVX_Usable (1 << 6) -#define bit_FMA4_Usable (1 << 7) +#define bit_FMA_Usable (1 << 7) +#define bit_FMA4_Usable (1 << 8) /* CPUID Feature flags. */ #define bit_SSE2 (1 << 26) @@ -56,6 +57,7 @@ # define index_Fast_Unaligned_Load FEATURE_INDEX_1*FEATURE_SIZE # define index_Prefer_PMINUB_for_stringop FEATURE_INDEX_1*FEATURE_SIZE # define index_AVX_Usable FEATURE_INDEX_1*FEATURE_SIZE +# define index_FMA_Usable FEATURE_INDEX_1*FEATURE_SIZE # define index_FMA4_Usable FEATURE_INDEX_1*FEATURE_SIZE #else /* __ASSEMBLER__ */ @@ -131,6 +133,8 @@ extern const struct cpu_features *__get_cpu_features (void) HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_OSXSAVE) # define CPUID_AVX \ HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_AVX) +# define CPUID_FMA \ + HAS_CPUID_FLAG (COMMON_CPUID_INDEX_1, ecx, bit_FMA) # define CPUID_FMA4 \ HAS_CPUID_FLAG (COMMON_CPUID_INDEX_80000001, ecx, bit_FMA4) @@ -140,7 +144,6 @@ extern const struct cpu_features *__get_cpu_features (void) # define HAS_SSSE3 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSSE3) # define HAS_SSE4_1 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_1) # define HAS_SSE4_2 HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_SSE4_2) -# define HAS_FMA HAS_CPU_FEATURE (COMMON_CPUID_INDEX_1, ecx, bit_FMA) # define index_Fast_Rep_String FEATURE_INDEX_1 # define index_Fast_Copy_Backward FEATURE_INDEX_1 @@ -148,6 +151,7 @@ extern const struct cpu_features *__get_cpu_features (void) # define index_Prefer_SSE_for_memop FEATURE_INDEX_1 # define index_Fast_Unaligned_Load FEATURE_INDEX_1 # define index_AVX_Usable FEATURE_INDEX_1 +# define index_FMA_Usable FEATURE_INDEX_1 # define index_FMA4_Usable FEATURE_INDEX_1 # define HAS_ARCH_FEATURE(name) \ @@ -159,6 +163,7 @@ extern const struct cpu_features *__get_cpu_features (void) # define HAS_PREFER_SSE_FOR_MEMOP HAS_ARCH_FEATURE (Prefer_SSE_for_memop) # define HAS_FAST_UNALIGNED_LOAD HAS_ARCH_FEATURE (Fast_Unaligned_Load) # define HAS_AVX HAS_ARCH_FEATURE (AVX_Usable) +# define HAS_FMA HAS_ARCH_FEATURE (FMA_Usable) # define HAS_FMA4 HAS_ARCH_FEATURE (FMA4_Usable) #endif /* __ASSEMBLER__ */ -- 1.7.2.3 From fc81079f382590db35d158ae455cadadbbe0bde3 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Tue, 1 May 2012 17:10:10 +0200 Subject: [PATCH] Fix missing _mcount@GLIBC_2.0 on powerpc32 (cherry picked from commit 261f485936b283f4327fc1f2fc8fd1705d805c12) --- sysdeps/powerpc/powerpc32/Makefile | 3 ++- sysdeps/powerpc/powerpc32/compat-ppc-mcount.S | 11 +++++++++++ sysdeps/powerpc/powerpc32/ppc-mcount.S | 6 +++++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 sysdeps/powerpc/powerpc32/compat-ppc-mcount.S diff --git a/sysdeps/powerpc/powerpc32/Makefile b/sysdeps/powerpc/powerpc32/Makefile index aa2d0b9..64f7900 100644 --- a/sysdeps/powerpc/powerpc32/Makefile +++ b/sysdeps/powerpc/powerpc32/Makefile @@ -6,8 +6,9 @@ sysdep-LDFLAGS += -msoft-float endif ifeq ($(subdir),gmon) -sysdep_routines += ppc-mcount +sysdep_routines += ppc-mcount compat-ppc-mcount static-only-routines += ppc-mcount +shared-only-routines += compat-ppc-mcount endif ifeq ($(subdir),misc) diff --git a/sysdeps/powerpc/powerpc32/compat-ppc-mcount.S b/sysdeps/powerpc/powerpc32/compat-ppc-mcount.S new file mode 100644 index 0000000..2a9cb24 --- /dev/null +++ b/sysdeps/powerpc/powerpc32/compat-ppc-mcount.S @@ -0,0 +1,11 @@ +#include + +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_15) + + compat_text_section +# define _mcount __compat_mcount +# include "ppc-mcount.S" +# undef _mcount + +compat_symbol (libc, __compat_mcount, _mcount, GLIBC_2_0) +#endif diff --git a/sysdeps/powerpc/powerpc32/ppc-mcount.S b/sysdeps/powerpc/powerpc32/ppc-mcount.S index 9a3c041..911638b 100644 --- a/sysdeps/powerpc/powerpc32/ppc-mcount.S +++ b/sysdeps/powerpc/powerpc32/ppc-mcount.S @@ -1,5 +1,5 @@ /* PowerPC-specific implementation of profiling support. - Copyright (C) 1997, 1999, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -57,7 +57,11 @@ ENTRY(_mcount) stw r4, 44(r1) cfi_offset (lr, -4) stw r5, 8(r1) +#ifndef SHARED bl JUMPTARGET(__mcount_internal) +#else + bl __mcount_internal@local +#endif /* Restore the registers... */ lwz r6, 8(r1) lwz r0, 44(r1) -- 1.7.2.3 From d126b22311ff50e933ac24560a5bee116468d6b3 Mon Sep 17 00:00:00 2001 From: H.J. Lu Date: Wed, 14 Nov 2012 15:44:40 -0800 Subject: [PATCH] Skip audit if l_reloc_result is NULL Cherry-pick commit 2e64d2659d3edaebc792ac596a9863f1626e5c25 --- elf/Makefile | 6 +++++- elf/dl-runtime.c | 22 +++++++++++++++++++++- elf/tst-audit8.c | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 elf/tst-audit8.c diff --git a/elf/Makefile b/elf/Makefile index 0c26ce5..a621a1c 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -138,7 +138,7 @@ tests += loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ tst-dlmodcount tst-dlopenrpath tst-deep1 \ tst-dlmopen1 tst-dlmopen2 tst-dlmopen3 \ unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \ - tst-audit1 tst-audit2 \ + tst-audit1 tst-audit2 tst-audit8 \ tst-stackguard1 tst-addr1 tst-thrlock \ tst-unique1 tst-unique2 tst-unique3 tst-unique4 \ tst-initorder tst-initorder2 tst-relsort1 @@ -1024,6 +1024,10 @@ $(objpfx)tst-audit7: $(objpfx)tst-auditmod7a.so $(objpfx)tst-audit7.out: $(objpfx)tst-auditmod7b.so tst-audit7-ENV = LD_AUDIT=$(objpfx)tst-auditmod7b.so +$(objpfx)tst-audit8: $(common-objpfx)math/libm.so +$(objpfx)tst-audit8.out: $(objpfx)tst-auditmod1.so +tst-audit8-ENV = LD_AUDIT=$(objpfx)tst-auditmod1.so + $(objpfx)tst-global1: $(libdl) $(objpfx)tst-global1.out: $(objpfx)testobj6.so $(objpfx)testobj2.so diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index fdaa364..009d366 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -1,5 +1,5 @@ /* On-demand PLT fixup for shared objects. - Copyright (C) 1995-2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1995-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -168,6 +168,26 @@ _dl_profile_fixup ( { void (*mcount_fct) (ElfW(Addr), ElfW(Addr)) = INTUSE(_dl_mcount); + if (l->l_reloc_result == NULL) + { + /* BZ #14843: ELF_DYNAMIC_RELOCATE is called before l_reloc_result + is allocated. We will get here if ELF_DYNAMIC_RELOCATE calls a + resolver function to resolve an IRELATIVE relocation and that + resolver calls a function that is not yet resolved (lazy). For + example, the resolver in x86-64 libm.so calls __get_cpu_features + defined in libc.so. Skip audit and resolve the external function + in this case. */ + *framesizep = -1; + return _dl_fixup ( +# ifdef ELF_MACHINE_RUNTIME_FIXUP_ARGS +# ifndef ELF_MACHINE_RUNTIME_FIXUP_PARAMS +# error Please define ELF_MACHINE_RUNTIME_FIXUP_PARAMS. +# endif + ELF_MACHINE_RUNTIME_FIXUP_PARAMS, +# endif + l, reloc_arg); + } + /* This is the address in the array where we store the result of previous relocations. */ struct reloc_result *reloc_result = &l->l_reloc_result[reloc_index]; diff --git a/elf/tst-audit8.c b/elf/tst-audit8.c new file mode 100644 index 0000000..63656b4 --- /dev/null +++ b/elf/tst-audit8.c @@ -0,0 +1 @@ +#include "../io/pwd.c" -- 1.7.2.3 From 914950f767030cf62da1672b9a117b59f5c1da6f Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 20 Nov 2012 19:29:23 +0100 Subject: [PATCH] sysdeps/sh/dl-machine.h: Define ELF_MACHINE_RUNTIME_FIXUP_PARAMS. Cherry-pick commit d072f3f7724d85ceaf230806660235f0cf2f9c3b --- sysdeps/sh/dl-machine.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h index 53656af..1bb5d15 100644 --- a/sysdeps/sh/dl-machine.h +++ b/sysdeps/sh/dl-machine.h @@ -1,6 +1,5 @@ /* Machine-dependent ELF dynamic relocation inline functions. SH version. - Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2011 - Free Software Foundation, Inc. + Copyright (C) 1999-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -116,6 +115,7 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) } #define ELF_MACHINE_RUNTIME_FIXUP_ARGS int plt_type +#define ELF_MACHINE_RUNTIME_FIXUP_PARAMS plt_type /* Mask identifying addresses reserved for the user program, where the dynamic linker should not map anything. */ -- 1.7.2.3