diff options
Diffstat (limited to 'posix')
-rw-r--r-- | posix/Makefile | 9 | ||||
-rw-r--r-- | posix/Versions | 4 | ||||
-rw-r--r-- | posix/bug-regex34.c | 46 | ||||
-rw-r--r-- | posix/bug-regex35.c | 52 | ||||
-rw-r--r-- | posix/regcomp.c | 72 | ||||
-rw-r--r-- | posix/regex_internal.h | 27 | ||||
-rw-r--r-- | posix/regexec.c | 16 | ||||
-rw-r--r-- | posix/tst-pathconf.c | 176 |
8 files changed, 330 insertions, 72 deletions
diff --git a/posix/Makefile b/posix/Makefile index 57672d8837..a728630203 100644 --- a/posix/Makefile +++ b/posix/Makefile @@ -86,7 +86,8 @@ tests := tstgetopt testfnm runtests runptests \ tst-rfc3484-3 \ tst-getaddrinfo3 tst-fnmatch2 tst-cpucount tst-cpuset \ bug-getopt1 bug-getopt2 bug-getopt3 bug-getopt4 \ - bug-getopt5 tst-getopt_long1 + bug-getopt5 tst-getopt_long1 bug-regex34 bug-regex35 \ + tst-pathconf xtests := bug-ga2 ifeq (yes,$(build-shared)) test-srcs := globtest @@ -199,6 +200,8 @@ bug-regex26-ENV = LOCPATH=$(common-objpfx)localedata bug-regex30-ENV = LOCPATH=$(common-objpfx)localedata bug-regex32-ENV = LOCPATH=$(common-objpfx)localedata bug-regex33-ENV = LOCPATH=$(common-objpfx)localedata +bug-regex34-ENV = LOCPATH=$(common-objpfx)localedata +bug-regex35-ENV = LOCPATH=$(common-objpfx)localedata tst-rxspencer-ARGS = --utf8 rxspencer/tests tst-rxspencer-ENV = LOCPATH=$(common-objpfx)localedata tst-pcre-ARGS = PCRE.tests @@ -207,11 +210,11 @@ bug-glob1-ARGS = "$(objpfx)" tst-execvp3-ARGS = --test-dir=$(objpfx) testcases.h: TESTS TESTS2C.sed - sed -f TESTS2C.sed < $< > $@T + LC_ALL=C sed -f TESTS2C.sed < $< > $@T mv -f $@T $@ ptestcases.h: PTESTS PTESTS2C.sed - sed -f PTESTS2C.sed < $< > $@T + LC_ALL=C sed -f PTESTS2C.sed < $< > $@T mv -f $@T $@ # Run a test on the header files we use. diff --git a/posix/Versions b/posix/Versions index 686c446bcd..1bc235acd2 100644 --- a/posix/Versions +++ b/posix/Versions @@ -1,7 +1,7 @@ libc { GLIBC_2.0 { # functions with special/multiple interfaces - __bsd_getpgrp; __setpgid; __getpgid; + __bsd_getpgrp; __getpgid; __setpgid; # functions with required interface outside normal name space _exit; @@ -114,7 +114,7 @@ libc { # under GLIBC_2.0; the first instance in the script is taken as the # default, so linux configurations put them in GLIBC_2.0 while other # configuration put them in GLIBC_2.3.2. - getresuid; getresgid; setresuid; setresgid; + getresgid; getresuid; setresgid; setresuid; } GLIBC_2.3.3 { sched_getaffinity; sched_setaffinity; diff --git a/posix/bug-regex34.c b/posix/bug-regex34.c new file mode 100644 index 0000000000..bb3b6138f8 --- /dev/null +++ b/posix/bug-regex34.c @@ -0,0 +1,46 @@ +/* Test re_search with multi-byte characters in UTF-8. + Copyright (C) 2013 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 + <http://www.gnu.org/licenses/>. */ + +#define _GNU_SOURCE 1 +#include <stdio.h> +#include <string.h> +#include <locale.h> +#include <regex.h> + +static int +do_test (void) +{ + struct re_pattern_buffer r; + /* ကျွန်ုပ်x */ + const char *s = "\xe1\x80\x80\xe1\x80\xbb\xe1\x80\xbd\xe1\x80\x94\xe1\x80\xba\xe1\x80\xaf\xe1\x80\x95\xe1\x80\xbax"; + + if (setlocale (LC_ALL, "en_US.UTF-8") == NULL) + { + puts ("setlocale failed"); + return 1; + } + memset (&r, 0, sizeof (r)); + + re_compile_pattern ("[^x]x", 5, &r); + /* This was triggering a buffer overflow. */ + re_search (&r, s, strlen (s), 0, strlen (s), 0); + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/posix/bug-regex35.c b/posix/bug-regex35.c new file mode 100644 index 0000000000..7957e7f860 --- /dev/null +++ b/posix/bug-regex35.c @@ -0,0 +1,52 @@ +/* Test regcomp with collating symbols in bracket expressions + Copyright (C) 2013 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 + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <string.h> +#include <locale.h> +#include <regex.h> + +static int +do_test (void) +{ + regex_t r; + + if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL) + { + puts ("setlocale failed"); + return 1; + } + + if (regcomp (&r, "[[.ch.]]", REG_NOSUB) != 0) + { + puts ("regcomp failed"); + return 1; + } + + if (regexec (&r, "ch", 0, 0, 0) != 0) + { + puts ("regexec failed"); + return 1; + } + + regfree (&r); + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/posix/regcomp.c b/posix/regcomp.c index 88bd581d96..578044155b 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -2776,40 +2776,29 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, /* Local function for parse_bracket_exp used in _LIBC environement. Seek the collating symbol entry correspondings to NAME. - Return the index of the symbol in the SYMB_TABLE. */ + Return the index of the symbol in the SYMB_TABLE, + or -1 if not found. */ auto inline int32_t __attribute ((always_inline)) - seek_collating_symbol_entry (name, name_len) - const unsigned char *name; - size_t name_len; + seek_collating_symbol_entry (const unsigned char *name, size_t name_len) { - int32_t hash = elem_hash ((const char *) name, name_len); - int32_t elem = hash % table_size; - if (symb_table[2 * elem] != 0) - { - int32_t second = hash % (table_size - 2) + 1; - - do - { - /* First compare the hashing value. */ - if (symb_table[2 * elem] == hash - /* Compare the length of the name. */ - && name_len == extra[symb_table[2 * elem + 1]] - /* Compare the name. */ - && memcmp (name, &extra[symb_table[2 * elem + 1] + 1], - name_len) == 0) - { - /* Yep, this is the entry. */ - break; - } + int32_t elem; - /* Next entry. */ - elem += second; - } - while (symb_table[2 * elem] != 0); - } - return elem; + for (elem = 0; elem < table_size; elem++) + if (symb_table[2 * elem] != 0) + { + int32_t idx = symb_table[2 * elem + 1]; + /* Skip the name of collating element name. */ + idx += 1 + extra[idx]; + if (/* Compare the length of the name. */ + name_len == extra[idx] + /* Compare the name. */ + && memcmp (name, &extra[idx + 1], name_len) == 0) + /* Yep, this is the entry. */ + return elem; + } + return -1; } /* Local function for parse_bracket_exp used in _LIBC environment. @@ -2818,8 +2807,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline unsigned int __attribute ((always_inline)) - lookup_collation_sequence_value (br_elem) - bracket_elem_t *br_elem; + lookup_collation_sequence_value (bracket_elem_t *br_elem) { if (br_elem->type == SB_CHAR) { @@ -2847,7 +2835,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, int32_t elem, idx; elem = seek_collating_symbol_entry (br_elem->opr.name, sym_name_len); - if (symb_table[2 * elem] != 0) + if (elem != -1) { /* We found the entry. */ idx = symb_table[2 * elem + 1]; @@ -2865,7 +2853,7 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, /* Return the collation sequence value. */ return *(unsigned int *) (extra + idx); } - else if (symb_table[2 * elem] == 0 && sym_name_len == 1) + else if (sym_name_len == 1) { /* No valid character. Match it as a single byte character. */ @@ -2887,11 +2875,8 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline reg_errcode_t __attribute ((always_inline)) - build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem) - re_charset_t *mbcset; - int *range_alloc; - bitset_t sbcset; - bracket_elem_t *start_elem, *end_elem; + build_range_exp (bitset_t sbcset, re_charset_t *mbcset, int *range_alloc, + bracket_elem_t *start_elem, bracket_elem_t *end_elem) { unsigned int ch; uint32_t start_collseq; @@ -2970,25 +2955,22 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token, auto inline reg_errcode_t __attribute ((always_inline)) - build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name) - re_charset_t *mbcset; - int *coll_sym_alloc; - bitset_t sbcset; - const unsigned char *name; + build_collating_symbol (bitset_t sbcset, re_charset_t *mbcset, + int *coll_sym_alloc, const unsigned char *name) { int32_t elem, idx; size_t name_len = strlen ((const char *) name); if (nrules != 0) { elem = seek_collating_symbol_entry (name, name_len); - if (symb_table[2 * elem] != 0) + if (elem != -1) { /* We found the entry. */ idx = symb_table[2 * elem + 1]; /* Skip the name of collating element name. */ idx += 1 + extra[idx]; } - else if (symb_table[2 * elem] == 0 && name_len == 1) + else if (name_len == 1) { /* No valid character, treat it as a normal character. */ diff --git a/posix/regex_internal.h b/posix/regex_internal.h index 21cada87d3..3c94fbed7d 100644 --- a/posix/regex_internal.h +++ b/posix/regex_internal.h @@ -98,7 +98,6 @@ # define BE(expr, val) __builtin_expect (expr, val) #else # define BE(expr, val) (expr) -# define inline #endif /* Number of single byte character. */ @@ -122,10 +121,8 @@ # define attribute_hidden #endif /* not _LIBC */ -#ifdef __GNUC__ -# define __attribute(arg) __attribute__ (arg) -#else -# define __attribute(arg) +#if __GNUC__ < 3 + (__GNUC_MINOR__ < 1) +# define __attribute__(arg) #endif extern const char __re_error_msgid[] attribute_hidden; @@ -379,7 +376,7 @@ typedef struct re_dfa_t re_dfa_t; #ifndef _LIBC # ifdef __i386__ -# define internal_function __attribute ((regparm (3), stdcall)) +# define internal_function __attribute__ ((regparm (3), stdcall)) # else # define internal_function # endif @@ -398,7 +395,7 @@ static void build_upper_buffer (re_string_t *pstr) internal_function; static void re_string_translate_buffer (re_string_t *pstr) internal_function; static unsigned int re_string_context_at (const re_string_t *input, int idx, int eflags) - internal_function __attribute ((pure)); + internal_function __attribute__ ((pure)); #endif #define re_string_peek_byte(pstr, offset) \ ((pstr)->mbs[(pstr)->cur_idx + offset]) @@ -687,7 +684,7 @@ typedef struct /* Inline functions for bitset operation. */ -static inline void +static void __attribute__ ((unused)) bitset_not (bitset_t set) { int bitset_i; @@ -695,7 +692,7 @@ bitset_not (bitset_t set) set[bitset_i] = ~set[bitset_i]; } -static inline void +static void __attribute__ ((unused)) bitset_merge (bitset_t dest, const bitset_t src) { int bitset_i; @@ -703,7 +700,7 @@ bitset_merge (bitset_t dest, const bitset_t src) dest[bitset_i] |= src[bitset_i]; } -static inline void +static void __attribute__ ((unused)) bitset_mask (bitset_t dest, const bitset_t src) { int bitset_i; @@ -713,8 +710,8 @@ bitset_mask (bitset_t dest, const bitset_t src) #ifdef RE_ENABLE_I18N /* Inline functions for re_string. */ -static inline int -internal_function __attribute ((pure)) +static int +internal_function __attribute__ ((pure, unused)) re_string_char_size_at (const re_string_t *pstr, int idx) { int byte_idx; @@ -726,8 +723,8 @@ re_string_char_size_at (const re_string_t *pstr, int idx) return byte_idx; } -static inline wint_t -internal_function __attribute ((pure)) +static wint_t +internal_function __attribute__ ((pure, unused)) re_string_wchar_at (const re_string_t *pstr, int idx) { if (pstr->mb_cur_max == 1) @@ -737,7 +734,7 @@ re_string_wchar_at (const re_string_t *pstr, int idx) # ifndef NOT_IN_libc static int -internal_function __attribute ((pure)) +internal_function __attribute__ ((pure, unused)) re_string_elem_size_at (const re_string_t *pstr, int idx) { # ifdef _LIBC diff --git a/posix/regexec.c b/posix/regexec.c index 7f2de857a7..5ca2bf67a0 100644 --- a/posix/regexec.c +++ b/posix/regexec.c @@ -197,7 +197,7 @@ static int group_nodes_into_DFAstates (const re_dfa_t *dfa, static int check_node_accept (const re_match_context_t *mctx, const re_token_t *node, int idx) internal_function; -static reg_errcode_t extend_buffers (re_match_context_t *mctx) +static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len) internal_function; /* Entry point for POSIX code. */ @@ -1160,7 +1160,7 @@ check_matching (re_match_context_t *mctx, int fl_longest_match, || (BE (next_char_idx >= mctx->input.valid_len, 0) && mctx->input.valid_len < mctx->input.len)) { - err = extend_buffers (mctx); + err = extend_buffers (mctx, next_char_idx + 1); if (BE (err != REG_NOERROR, 0)) { assert (err == REG_ESPACE); @@ -1738,7 +1738,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, int next_state_log_idx) && mctx->input.valid_len < mctx->input.len)) { reg_errcode_t err; - err = extend_buffers (mctx); + err = extend_buffers (mctx, next_state_log_idx + 1); if (BE (err != REG_NOERROR, 0)) return err; } @@ -2792,7 +2792,7 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx) if (bkref_str_off >= mctx->input.len) break; - err = extend_buffers (mctx); + err = extend_buffers (mctx, bkref_str_off + 1); if (BE (err != REG_NOERROR, 0)) return err; @@ -4102,7 +4102,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, static reg_errcode_t internal_function __attribute_warn_unused_result__ -extend_buffers (re_match_context_t *mctx) +extend_buffers (re_match_context_t *mctx, int min_len) { reg_errcode_t ret; re_string_t *pstr = &mctx->input; @@ -4111,8 +4111,10 @@ extend_buffers (re_match_context_t *mctx) if (BE (INT_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0)) return REG_ESPACE; - /* Double the lengthes of the buffers. */ - ret = re_string_realloc_buffers (pstr, MIN (pstr->len, pstr->bufs_len * 2)); + /* Double the lengthes of the buffers, but allocate at least MIN_LEN. */ + ret = re_string_realloc_buffers (pstr, + MAX (min_len, + MIN (pstr->len, pstr->bufs_len * 2))); if (BE (ret != REG_NOERROR, 0)) return ret; diff --git a/posix/tst-pathconf.c b/posix/tst-pathconf.c new file mode 100644 index 0000000000..7627a24d8d --- /dev/null +++ b/posix/tst-pathconf.c @@ -0,0 +1,176 @@ +/* Test that values of pathconf and fpathconf are consistent for a file. + Copyright (C) 2013 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 + <http://www.gnu.org/licenses/>. */ + +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + + +static void prepare (void); +#define PREPARE(argc, argv) prepare () + +static int do_test (void); +#define TEST_FUNCTION do_test () + +#include "../test-skeleton.c" + +static int dir_fd; +static char *dirbuf; + +static void +prepare (void) +{ + size_t test_dir_len = strlen (test_dir); + static const char dir_name[] = "/tst-pathconf.XXXXXX"; + + size_t dirbuflen = test_dir_len + sizeof (dir_name); + dirbuf = malloc (dirbuflen); + if (dirbuf == NULL) + { + puts ("Out of memory"); + exit (1); + } + + snprintf (dirbuf, dirbuflen, "%s%s", test_dir, dir_name); + if (mkdtemp (dirbuf) == NULL) + { + printf ("Cannot create temporary directory: %s\n", strerror (errno)); + exit (1); + } + + add_temp_file (dirbuf); + + dir_fd = open (dirbuf, O_RDONLY); + if (dir_fd == -1) + { + printf ("Cannot open directory: %s\n", strerror (errno)); + exit (1); + } +} + + +static int +do_test (void) +{ + int ret = 0; + static const char *fifo_name = "some-fifo"; + + size_t filenamelen = strlen (dirbuf) + strlen (fifo_name) + 2; + char *filename = malloc (filenamelen); + + snprintf (filename, filenamelen, "%s/%s", dirbuf, fifo_name); + + /* Create a fifo in the directory. */ + int e = mkfifo (filename, 0777); + if (e == -1) + { + printf ("fifo creation failed (%s)\n", strerror (errno)); + ret = 1; + goto out_nofifo; + } + + long dir_pathconf = pathconf (dirbuf, _PC_PIPE_BUF); + + if (dir_pathconf < 0) + { + printf ("pathconf on directory failed: %s\n", strerror (errno)); + ret = 1; + goto out_nofifo; + } + + long fifo_pathconf = pathconf (filename, _PC_PIPE_BUF); + + if (fifo_pathconf < 0) + { + printf ("pathconf on file failed: %s\n", strerror (errno)); + ret = 1; + goto out_nofifo; + } + + int fifo = open (filename, O_RDONLY | O_NONBLOCK); + + if (fifo < 0) + { + printf ("fifo open failed (%s)\n", strerror (errno)); + ret = 1; + goto out_nofifo; + } + + long dir_fpathconf = fpathconf (dir_fd, _PC_PIPE_BUF); + + if (dir_fpathconf < 0) + { + printf ("fpathconf on directory failed: %s\n", strerror (errno)); + ret = 1; + goto out; + } + + long fifo_fpathconf = fpathconf (fifo, _PC_PIPE_BUF); + + if (fifo_fpathconf < 0) + { + printf ("fpathconf on file failed: %s\n", strerror (errno)); + ret = 1; + goto out; + } + + if (fifo_pathconf != fifo_fpathconf) + { + printf ("fifo pathconf (%ld) != fifo fpathconf (%ld)\n", fifo_pathconf, + fifo_fpathconf); + ret = 1; + goto out; + } + + if (dir_pathconf != fifo_pathconf) + { + printf ("directory pathconf (%ld) != fifo pathconf (%ld)\n", + dir_pathconf, fifo_pathconf); + ret = 1; + goto out; + } + + if (dir_fpathconf != fifo_fpathconf) + { + printf ("directory fpathconf (%ld) != fifo fpathconf (%ld)\n", + dir_fpathconf, fifo_fpathconf); + ret = 1; + goto out; + } + +out: + close (fifo); +out_nofifo: + close (dir_fd); + + if (unlink (filename) != 0) + { + printf ("Could not remove fifo (%s)\n", strerror (errno)); + ret = 1; + } + + if (rmdir (dirbuf) != 0) + { + printf ("Could not remove directory (%s)\n", strerror (errno)); + ret = 1; + } + + return ret; +} |