From dfab349bdb79376a7aa2e3eb71bab5441d0d3c1a Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Nov 03 2010 11:45:05 +0000 Subject: prevent sort from assertion failure (#647938) ... in case LC_CTYPE does not match LC_TIME --- diff --git a/coreutils-i18n.patch b/coreutils-i18n.patch index a2960a8..3fa93c3 100644 --- a/coreutils-i18n.patch +++ b/coreutils-i18n.patch @@ -1,3 +1,21 @@ + lib/linebuffer.h | 8 + + src/cut.c | 420 ++++++++++++++++++++++++++-- + src/expand.c | 160 +++++++++++- + src/fold.c | 309 +++++++++++++++++++-- + src/join.c | 343 ++++++++++++++++++++--- + src/pr.c | 431 ++++++++++++++++++++++++++--- + src/sort.c | 692 ++++++++++++++++++++++++++++++++++++++++++++-- + src/unexpand.c | 226 +++++++++++++++- + src/uniq.c | 259 +++++++++++++++++- + tests/Makefile.am | 5 + + tests/misc/cut | 4 +- + tests/misc/mb1.I | 4 + + tests/misc/mb1.X | 4 + + tests/misc/mb2.I | 4 + + tests/misc/mb2.X | 4 + + tests/misc/sort-mb-tests | 58 ++++ + 16 files changed, 2754 insertions(+), 177 deletions(-) + diff -urNp coreutils-8.0-orig/lib/linebuffer.h coreutils-8.0/lib/linebuffer.h --- coreutils-8.0-orig/lib/linebuffer.h 2009-10-06 10:59:48.000000000 +0200 +++ coreutils-8.0/lib/linebuffer.h 2009-10-07 10:07:16.000000000 +0200 @@ -2429,12 +2447,8 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c #include "system.h" #include "argmatch.h" #include "error.h" -@@ -122,14 +131,38 @@ static int decimal_point; - /* Thousands separator; if -1, then there isn't one. */ - static int thousands_sep; +@@ -125,12 +134,34 @@ static int thousands_sep; -+static int force_general_numcompare = 0; -+ /* Nonzero if the corresponding locales are hard. */ static bool hard_LC_COLLATE; -#if HAVE_NL_LANGINFO @@ -2469,7 +2483,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* The kind of blanks for '-b' to skip in various options. */ enum blanktype { bl_start, bl_end, bl_both }; -@@ -268,13 +301,11 @@ static bool reverse; +@@ -269,13 +300,11 @@ static bool reverse; they were read if all keys compare equal. */ static bool stable; @@ -2486,7 +2500,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* Flag to remove consecutive duplicate lines from the output. Only the last of a sequence of equal lines will be output. */ -@@ -712,6 +743,44 @@ reap_some (void) +@@ -713,6 +742,44 @@ reap_some (void) update_proc (pid); } @@ -2531,7 +2545,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* Clean up any remaining temporary files. */ static void -@@ -1093,7 +1162,7 @@ zaptemp (const char *name) +@@ -1094,7 +1161,7 @@ zaptemp (const char *name) free (node); } @@ -2540,7 +2554,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c static int struct_month_cmp (const void *m1, const void *m2) -@@ -1108,7 +1177,7 @@ struct_month_cmp (const void *m1, const +@@ -1109,7 +1176,7 @@ struct_month_cmp (const void *m1, const void *m2) /* Initialize the character class tables. */ static void @@ -2549,7 +2563,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { size_t i; -@@ -1120,7 +1189,7 @@ inittables (void) +@@ -1121,7 +1188,7 @@ inittables (void) fold_toupper[i] = toupper (i); } @@ -2558,7 +2572,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* If we're not in the "C" locale, read different names for months. */ if (hard_LC_TIME) { -@@ -1202,6 +1271,64 @@ specify_nmerge (int oi, char c, char con +@@ -1203,6 +1270,84 @@ specify_nmerge (int oi, char c, char const *s) xstrtol_fatal (e, oi, c, long_options, s); } @@ -2567,12 +2581,25 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c +inittables_mb (void) +{ + int i, j, k, l; -+ char *name, *s; ++ char *name, *s, *lc_time, *lc_ctype; + size_t s_len, mblength; + char mbc[MB_LEN_MAX]; + wchar_t wc, pwc; + mbstate_t state_mb, state_wc; + ++ lc_time = setlocale (LC_TIME, ""); ++ if (lc_time) ++ lc_time = xstrdup (lc_time); ++ ++ lc_ctype = setlocale (LC_CTYPE, ""); ++ if (lc_ctype) ++ lc_ctype = xstrdup (lc_ctype); ++ ++ if (lc_time && lc_ctype) ++ /* temporarily set LC_CTYPE to match LC_TIME, so that we can convert ++ * the names of months to upper case */ ++ setlocale (LC_CTYPE, lc_time); ++ + for (i = 0; i < MONTHS_PER_YEAR; i++) + { + s = (char *) nl_langinfo (ABMON_1 + i); @@ -2617,13 +2644,20 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c + } + qsort ((void *) monthtab, MONTHS_PER_YEAR, + sizeof (struct month), struct_month_cmp); ++ ++ if (lc_time && lc_ctype) ++ /* restore the original locales */ ++ setlocale (LC_CTYPE, lc_ctype); ++ ++ free (lc_ctype); ++ free (lc_time); +} +#endif + /* Specify the amount of main memory to use when sorting. */ static void specify_sort_size (int oi, char c, char const *s) -@@ -1412,7 +1539,7 @@ buffer_linelim (struct buffer const *buf +@@ -1413,7 +1558,7 @@ buffer_linelim (struct buffer const *buf) by KEY in LINE. */ static char * @@ -2632,7 +2666,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { char *ptr = line->text, *lim = ptr + line->length - 1; size_t sword = key->sword; -@@ -1421,10 +1548,10 @@ begfield (const struct line *line, const +@@ -1422,10 +1567,10 @@ begfield (const struct line *line, const struct keyfield *key) /* The leading field separator itself is included in a field when -t is absent. */ @@ -2645,7 +2679,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c ++ptr; if (ptr < lim) ++ptr; -@@ -1450,11 +1577,70 @@ begfield (const struct line *line, const +@@ -1451,11 +1596,70 @@ begfield (const struct line *line, const struct keyfield *key) return ptr; } @@ -2717,7 +2751,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { char *ptr = line->text, *lim = ptr + line->length - 1; size_t eword = key->eword, echar = key->echar; -@@ -1469,10 +1655,10 @@ limfield (const struct line *line, const +@@ -1470,10 +1674,10 @@ limfield (const struct line *line, const struct keyfield *key) `beginning' is the first character following the delimiting TAB. Otherwise, leave PTR pointing at the first `blank' character after the preceding field. */ @@ -2730,7 +2764,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c ++ptr; if (ptr < lim && (eword || echar)) ++ptr; -@@ -1518,10 +1704,10 @@ limfield (const struct line *line, const +@@ -1519,10 +1723,10 @@ limfield (const struct line *line, const struct keyfield *key) */ /* Make LIM point to the end of (one byte past) the current field. */ @@ -2743,7 +2777,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c if (newlim) lim = newlim; } -@@ -1552,6 +1738,113 @@ limfield (const struct line *line, const +@@ -1553,6 +1757,113 @@ limfield (const struct line *line, const struct keyfield *key) return ptr; } @@ -2857,7 +2891,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* Fill BUF reading from FP, moving buf->left bytes from the end of buf->buf to the beginning first. If EOF is reached and the file wasn't terminated by a newline, supply one. Set up BUF's line -@@ -1634,8 +1927,24 @@ fillbuf (struct buffer *buf, FILE *fp, c +@@ -1635,8 +1946,24 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file) else { if (key->skipsblanks) @@ -2884,7 +2918,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c line->keybeg = line_start; } } -@@ -1673,7 +1982,7 @@ fillbuf (struct buffer *buf, FILE *fp, c +@@ -1674,7 +2001,7 @@ fillbuf (struct buffer *buf, FILE *fp, char const *file) hideously fast. */ static int @@ -2893,7 +2927,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { while (blanks[to_uchar (*a)]) a++; -@@ -1782,6 +2091,25 @@ human_numcompare (const char *a, const c +@@ -1783,6 +2110,25 @@ human_numcompare (const char *a, const char *b, struct keyfield *key) : strnumcmp (a, b, decimal_point, thousands_sep)); } @@ -2919,7 +2953,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c static int general_numcompare (const char *sa, const char *sb) { -@@ -1815,7 +2143,7 @@ general_numcompare (const char *sa, cons +@@ -1816,7 +2162,7 @@ general_numcompare (const char *sa, const char *sb) Return 0 if the name in S is not recognized. */ static int @@ -2928,7 +2962,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { size_t lo = 0; size_t hi = MONTHS_PER_YEAR; -@@ -1996,11 +2324,80 @@ compare_version (char *restrict texta, s +@@ -1997,11 +2343,80 @@ compare_version (char *restrict texta, size_t lena, return diff; } @@ -3010,7 +3044,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c { struct keyfield *key = keylist; -@@ -2180,6 +2576,179 @@ keycompare (const struct line *a, const +@@ -2181,6 +2596,179 @@ keycompare (const struct line *a, const struct line *b) return key->reverse ? -diff : diff; } @@ -3190,7 +3224,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c /* Compare two lines A and B, returning negative, zero, or positive depending on whether A compares less than, equal to, or greater than B. */ -@@ -3178,7 +3747,7 @@ main (int argc, char **argv) +@@ -3179,7 +3767,7 @@ main (int argc, char **argv) initialize_exit_failure (SORT_FAILURE); hard_LC_COLLATE = hard_locale (LC_COLLATE); @@ -3199,7 +3233,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c hard_LC_TIME = hard_locale (LC_TIME); #endif -@@ -3199,6 +3768,27 @@ main (int argc, char **argv) +@@ -3200,6 +3788,27 @@ main (int argc, char **argv) thousands_sep = -1; } @@ -3227,7 +3261,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c have_read_stdin = false; inittables (); -@@ -3459,13 +4049,35 @@ main (int argc, char **argv) +@@ -3461,13 +4070,35 @@ main (int argc, char **argv) case 't': { @@ -3267,7 +3301,7 @@ diff -urNp coreutils-8.0-orig/src/sort.c coreutils-8.0/src/sort.c else { /* Provoke with `sort -txx'. Complain about -@@ -3476,9 +4088,12 @@ main (int argc, char **argv) +@@ -3478,9 +4109,12 @@ main (int argc, char **argv) quote (optarg)); } } diff --git a/coreutils.spec b/coreutils.spec index 640630a..3a252b9 100644 --- a/coreutils.spec +++ b/coreutils.spec @@ -1,7 +1,7 @@ Summary: A set of basic GNU tools commonly used in shell scripts Name: coreutils Version: 8.4 -Release: 9%{?dist} +Release: 10%{?dist} License: GPLv3+ Group: System Environment/Base Url: http://www.gnu.org/software/coreutils/ @@ -356,6 +356,10 @@ fi %{_libdir}/coreutils %changelog +* Wed Nov 03 2010 Kamil Dudka - 8.4-10 +- prevent sort from assertion failure in case LC_CTYPE does not match LC_TIME + (#647938) + * Fri Oct 01 2010 Ondrej Vasik - 8.4-9 - various fixes for case conversion in tr(#611274) - change assertion failure for invalid multibyte input