summaryrefslogtreecommitdiff
path: root/src/regex
AgeCommit message (Collapse)AuthorLines
2015-03-30regex: fix character class repetitionsSzabolcs Nagy-0/+5
Internally regcomp needs to copy some iteration nodes before translating the AST into TNFA representation. Literal nodes were not copied correctly: the class type and list of negated class types were not copied so classes were ignored (in the non-negated case an ignored char class caused the literal to match everything). This affects iterations when the upper bound is finite, larger than one or the lower bound is larger than one. So eg. the EREs [[:digit:]]{2} [^[:space:]ab]{1,4} were treated as .{2} [^ab]{1,4} The fix is done with minimal source modification to copy the necessary fields, but the AST preparation and node handling code of tre will need to be cleaned up for clarity. (cherry picked from commit c498efe117539a9d40d90b588c033316701c4b3e)
2015-03-30fix regcomp handling of backslash followed by high byteRich Felker-4/+1
the regex parser handles the (undefined) case of an unexpected byte following a backslash as a literal. however, instead of correctly decoding a character, it was treating the byte value itself as a character. this was not only semantically unjustified, but turned out to be dangerous on archs where plain char is signed: bytes in the range 252-255 alias the internal codes -4 through -1 used for special types of literal nodes in the AST. analogous to commit 39dfd58417ef642307d90306e1c7e50aaec5a35c in mainline. it's unclear whether the same crash that affected mainline is possible in the older regcomp code in 1.0.x, but conceptually the bug is the same.
2015-03-30fix memory leak in regexec when input contains illegal sequenceSzabolcs Nagy-5/+6
(cherry picked from commit 546f6b322bcafa2452925c19f9607d9689c75f95)
2014-07-28fix crash in regexec for nonzero nmatch argument with REG_NOSUBRich Felker-0/+1
per POSIX, the nmatch and pmatch arguments are ignored when the regex was compiled with REG_NOSUB. (cherry picked from commit 72ed3d47e567b1635a35d3c1d174c8a8b2787e30)
2013-12-12include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy-3/+0
2013-12-02implement FNM_LEADING_DIR extension flag in fnmatchRich Felker-2/+9
previously this flag was defined and accepted as a no-op, possibly breaking some software that uses it. given the choice to remove the definition and possibly break applications that were already working, or simply implement the feature, the latter turned out to be easy enough to make the decision easy. in the case where the FNM_PATHNAME flag is also set, this implementation is clean and essentially optimal. otherwise, it's an inefficient "brute force" implementation. at some point, when cleaning up and refactoring this code, I may add a more direct code path for handling FNM_LEADING_DIR in the non-FNM_PATHNAME case, but at this point my main interest is avoiding introducing new bugs in the code that implements the standard fnmatch features specified by POSIX.
2013-12-01fix fnmatch corner cases related to escapingRich Felker-4/+4
the FNM_PATHNAME logic for advancing by /-delimited components was incorrect when the / character was escaped (i.e. \/), and a final \ at the end of pattern was not handled correctly.
2013-12-01fix the end of string matching in fnmatch with FNM_PATHNAMESzabolcs Nagy-2/+2
a '/' in the pattern could be incorrectly matched against the terminating null byte in the string causing arbitrarily long sequence of out-of-bounds access in fnmatch("/","",FNM_PATHNAME)
2013-10-07fix allocation sizes in regcompSzabolcs Nagy-4/+4
sizeof had incorrect argument in a few places, the size was always large enough so the issue was not critical.
2013-02-01revert regex "cleanup" that seems unjustified and may break backtrackingRich Felker-0/+3
it's not clear to me at the moment whether the code that was removed (and which is now being re-added) is needed, but it's far from being a no-op, and i don't want to risk breaking regex in this release.
2013-01-15remove unused "params" related code from regexSzabolcs Nagy-21/+11
some structs and functions had reference to the params feature of tre that is not used by the code anymore
2013-01-14regex: remove an unused local variable from regexecSzabolcs Nagy-3/+0
pos_start local variable is not used in tre_tnfa_run_backtrack
2012-09-06use restrict everywhere it's required by c99 and/or posix 2008Rich Felker-5/+5
to deal with the fact that the public headers may be used with pre-c99 compilers, __restrict is used in place of restrict, and defined appropriately for any supported compiler. we also avoid the form [restrict] since older versions of gcc rejected it due to a bug in the original c99 standard, and instead use the form *restrict.
2012-05-25fix regex on armRich Felker-1/+1
TRE has a broken assumption that wchar_t is signed, which is a sane expectation, but not required by the standard, and false on ARM's ABI. i leave tre_char_t as wchar_t for now, since a pointer to it is directly passed to functions that need pointer to wchar_t. it does not seem to break anything. and since the maximum unicode scalar value is 0x10ffff, just use that explicitly rather than using the max value of any particular C type.
2012-05-13remove some no-op end of string tests from regex parserRich Felker-4/+0
these are cruft from the original code which used an explicit string length rather than null termination. i blindly converted all the checks to null terminator checks, without noticing that in several cases, the subsequent switch statement would automatically handle the null byte correctly.
2012-05-13another BRE fix: in ^*, * is literalRich Felker-0/+2
i don't understand why this has to be conditional on being in BRE mode, but enabling this code unconditionally breaks a huge number of ERE test cases.
2012-05-07fix error checking for \ at end of regex (this was broken previously)Rich Felker-1/+1
2012-05-07fix copy and paste error in regex code causing mishandling of \) in BRERich Felker-1/+1
2012-05-07fix regex breakage in last commit (failure to handle empty regex, etc.)Rich Felker-4/+1
2012-05-07fix ugly bugs in TRE regex parserRich Felker-60/+31
1. * in BRE is not special at the beginning of the regex or a subexpression. this broke ncurses' build scripts. 2. \\( in BRE is a literal \ followed by a literal (, not a literal \ followed by a subexpression opener. 3. the ^ in \\(^ in BRE is a literal ^ only at the beginning of the entire BRE. POSIX allows treating it as an anchor at the beginning of a subexpression, but TRE's code for checking if it was at the beginning of a subexpression was wrong, and fixing it for the sake of supporting a non-portable usage was too much trouble when just removing this non-portable behavior was much easier. this patch also moved lots of the ugly logic for empty atom checking out of the default/literal case and into new cases for the relevant characters. this should make parsing faster and make the code smaller. if nothing else it's a lot more readable/logical. at some point i'd like to revisit and overhaul lots of this code...
2012-04-28new fnmatch implementationRich Felker-131/+273
unlike the old one, this one's algorithm does not suffer from potential stack overflow issues or pathologically bad performance on certain patterns. instead of backtracking, it uses a matching algorithm which I have not seen before (unsure whether I invented or re-invented it) that runs in O(1) space and O(nm) time. it may be possible to improve the time to O(n), but not without significantly greater complexity.
2012-04-26update fnmatch to POSIX 2008 semanticsRich Felker-4/+11
an invalid bracket expression must be treated as if the opening bracket were just a literal character. this is to fix a bug whereby POSIX left the behavior of the "[" shell command undefined due to it being an invalid bracket expression.
2012-04-14fix signedness error handling invalid multibyte sequences in regexecRich Felker-2/+2
the "< 0" test was always false due to use of an unsigned type. this resulted in infinite loops on 32-bit machines (adding -1U to a pointer is the same as adding -1) and crashes on 64-bit machines (offsetting the string pointer by 4gb-1b when an illegal sequence was hit).
2012-04-13remove invalid code from TRERich Felker-14/+0
TRE wants to treat + and ? after a +, ?, or * as special; ? means ungreedy and + is reserved for future use. however, this is non-conformant. although redundant, these redundant characters have well-defined (no-op) meaning for POSIX ERE, and are actually _literal_ characters (which TRE is wrongly ignoring) in POSIX BRE mode. the simplest fix is to simply remove the unneeded nonstandard functionality. as a plus, this shaves off a small amount of bloat.
2012-04-13fix broken regerror (typo) and missing messageRich Felker-2/+2
2012-03-20upgrade to latest upstream TRE regex code (0.8.0)Rich Felker-1168/+1037
the main practical results of this change are 1. the regex code is no longer subject to LGPL; it's now 2-clause BSD 2. most (all?) popular nonstandard regex extensions are supported I hesitate to call this a "sync" since both the old and new code are heavily modified. in one sense, the old code was "more severely" modified, in that it was actively hostile to non-strictly-conforming expressions. on the other hand, the new code has eliminated the useless translation of the entire regex string to wchar_t prior to compiling, and now only converts multibyte character literals as needed. in the future i may use this modified TRE as a basis for writing the long-planned new regex engine that will avoid multibyte-to-wide character conversion entirely by compiling multibyte bracket expressions specific to UTF-8.
2012-01-23make glob mark symlinks-to-directories with the GLOB_MARK flagRich Felker-1/+1
POSIX is unclear on whether it should, but all historical implementations seem to behave this way, and it seems more useful to applications.
2012-01-22support GLOB_PERIOD flag (GNU extension) to glob functionRich Felker-1/+2
patch by sh4rm4
2011-06-16duplicate re_nsub in LSB/glibc ABI compatible locationRich Felker-1/+1
2011-06-06fix handling of d_name in struct direntRich Felker-3/+2
basically there are 3 choices for how to implement this variable-size string member: 1. C99 flexible array member: breaks using dirent.h with pre-C99 compiler. 2. old way: length-1 string: generates array bounds warnings in caller. 3. new way: length-NAME_MAX string. no problems, simplifies all code. of course the usable part in the pointer returned by readdir might be shorter than NAME_MAX+1 bytes, but that is allowed by the standard and doesn't hurt anything.
2011-06-05safety fix for glob's vla usage: disallow patterns longer than PATH_MAXRich Felker-0/+2
this actually inadvertently disallows some valid patterns with redundant / or * characters, but it's better than allowing unbounded vla allocation. eventually i'll write code to move the pattern to the stack and eliminate redundancy to ensure that it fits in PATH_MAX at the beginning of glob. this would also allow it to be modified in place for passing to fnmatch rather than copied at each level of recursion.
2011-06-05eliminate (harmless in this case) vla usage in fnmatch.cRich Felker-1/+1
2011-04-07fix bug in TRE found by clang (typo && instead of &)Rich Felker-1/+1
2011-02-12initial check-in, version 0.5.0v0.5.0Rich Felker-0/+5364