summaryrefslogtreecommitdiffstats
path: root/lib/libc/regex/regcomp.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC r317707:brooks2017-05-091-0/+4
| | | | | | | | | | | | | | | | | | | Correct an out-of-bounds read in regcomp when the RE is bad. When passed the invalid regular expression "a**", the error is eventually detected and seterr() is called. It sets p->error appropriatly and p->next and p->end to nuls which is a never used char nuls[10] which is zeros due to .bss initialization. Unfortunatly, p_ere_exp() and p_simp_re() both have fall through cases where they set the error, decrement p->next and access it which means a read from whatever .bss variable comes before nuls. Found with regex_test:repet_multi and CHERI bounds checking. Reviewed by: ngie, pfg, emaste Obtained from: CheriBSD Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D10541
* MFC r317346:pfg2017-05-071-12/+11
| | | | | | | | | regex: unsign and constify some variables. Taking some hints from the regex variant in nvi(1) and higher-level compiler warnings, update some types in our regex(3) implementation. Joint work with: Kyle Evans
* MFC r315162:pfg2017-04-071-6/+6
| | | | | | | | libc: provide some bounds-checking through reallocarray(3). reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication.
* MFC r302824ache2016-08-171-6/+5
| | | | | | | | | | | | | 1) Eliminate possibility to call __*collate_range_cmp() with inclomplete locale (which cause core dump) by removing whole 'table' argument by which it passed. 2) Restore __collate_range_cmp() in __sccl(). 3) Collating [a-z] range in regcomp() work only for single bytes locales (we can't do it now for other ones). In previous code only first 256 wchars are considered and all others are just silently dropped from the range.
* libc/locale: Fix type breakage in __collate_range_cmp().pfg2016-06-051-3/+3
| | | | | | | | | | | | | | | | When collation support was brought in, the second and third arguments in __collate_range_cmp() were changed from int to wchar_t, breaking the ABI. Change them to a "char" type which makes more sense and keeps the ABI compatible. Also introduce __wcollate_range_cmp() which does work with wide characters. This function is used only internally in libc so we don't export it. Use the new function in glob(3), fnmatch(3), and regexec(3). PR: 179721 Suggested by: ache. jilles MFC after: 3 weeks (perhaps partial only)
* libc: spelling fixes.pfg2016-04-301-1/+1
| | | | Mostly on comments.
* computematchjumps(): fix allocator sizeof operand mismatch.pfg2015-04-221-2/+2
| | | | | | Mostly cosmetical warning. Found by: Clang static analyzer
* regex(3): Fix uninitialized pointer values.pfg2015-02-201-2/+2
| | | | | CID: 405582 (also clang static checker) CID: 1018724
* Disallow pattern spaces which would cause intermediate calculations todelphij2015-02-141-0/+17
| | | | | | | | overflow size_t. Obtained from: DragonFly (2841837793bd095a82f477e9c370cfe6cfb3862c dillon) Security: CERT VU#695940 MFC after: 3 days
* Plug a memory leak.delphij2014-12-191-1/+3
| | | | | Obtained from: DragonFlyBSD (commit 5119ece) MFC after: 2 weeks
* regex(3): Add support for \< and \> word delimiterspfg2014-06-301-1/+17
| | | | | | | | | | | | | | | | | | Solaris and other OSs have support for \< and \> as word delimiters in utilities like sed(1). These are useful to have for general compatiblity with Solaris but should be avoided for portability with other systems, including the traditional BSDs. Bump __FreeBSD_version as this is likely to affect some userland utilities. Reference: https://www.illumos.org/issues/516 PR: bin/153257 Obtained from: Illumos MFC after: 1 month
* Revert r267675:pfg2014-06-211-6/+6
| | | | | | | | The code doesn't really benefit of using reallocf() in this case. Also, the realloc() results being assigned temporary variable which makes blind replacement with reallocf() mostly useless. Pointed out by: stefanf, bde
* regex: Make use of reallocf().pfg2014-06-201-6/+6
| | | | | | | | | | | | Use of reallocf is useful in libraries as we are not certain the application will exit after NULL. This somewhat reduces portability but if since you are building this as part of libc it is likely you have our non-standard reallocf(3) already. Reviewed by: ache MFC after: 5 days
* Revert r265367:pfg2014-05-051-1/+1
| | | | | | | | Use of calloc instead of malloc in regex (from OpenBSD). In this case the change makes no sense since we are using realloc() later. Reported by: ache
* regex: Use calloc instead of malloc.pfg2014-05-051-1/+1
| | | | | | | Mostly to reduce differences with OpenBSD. Obtained from: OpenBSD (CVS rev. 1.17) MFC after: 3 days
* regex: Remove some unreachable breaks.pfg2014-05-011-1/+0
| | | | | | | | | This is based on a much bigger cleanup done in Illumos. Reference: https://www.illumos.org/issues/2077 MFC after: 1 week
* Fix assignment of maximum bounadary.delphij2013-03-011-1/+1
| | | | | | Submitted by: Sascha Wildner <saw online de> Obtained from: DragonFly rev fd39c81ba220f7ad6e4dc9b30d45e828cf58a1ad MFC after: 2 weeks
* Remove some duplicated copyright notices.theraven2012-03-061-5/+0
| | | | Approved by: dim (mentor)
* Implement xlocale APIs from Darwin, mainly for use by libc++. This adds atheraven2011-11-201-4/+16
| | | | | | | | | | | | load of _l suffixed versions of various standard library functions that use the global locale, making them take an explicit locale parameter. Also adds support for per-thread locales. This work was funded by the FreeBSD Foundation. Please test any code you have that uses the C standard locale functions! Reviewed by: das (gdtoa changes) Approved by: dim (mentor)
* Converting int to wint_t leads to broekn comparison of raw charkevlo2011-11-111-8/+8
| | | | | | and encoded wint_t. Spotted by: ache
* - Don't handle out-of-memory conditionkevlo2011-11-101-20/+21
| | | | | | | - Fix types of function arguments match their declaration Reviewed by: delphij Obtained from: NetBSD
* Diff reduction against other *BSDs: ANSIfy functiondelphij2007-06-111-113/+49
| | | | prototypes. No function changes.
* Per Regents of the University of Calfornia letter, remove advertisingimp2007-01-091-4/+0
| | | | | | clause. # If I've done so improperly on a file, please let me know.
* Directly include <runetype.h> for _CurrentRuneLocale, <_ctype.h> doesn'tstefanf2004-10-031-0/+1
| | | | include it in all cases.
* Fix two problems with REG_ICASE that were introduced with the addition oftjr2004-09-051-13/+10
| | | | | | | | | | | multibyte character support: - In CHadd(), avoid writing past the end of the character set bitmap when the opposite-case counterpart of wide characters with values less than NC have values greater than or equal to NC. - In CHaddtype(), fix a braino that caused alphabetic characters to be added to all character classes! (but only with REG_ICASE) PR: 71367
* Make regular expression matching aware of multibyte characters. The generaltjr2004-07-121-261/+255
| | | | | | | | | | | | | | | | | idea is that we perform multibyte->wide character conversion while parsing and compiling, then convert byte sequences to wide characters when they're needed for comparison and stepping through the string during execution. As with tr(1), the main complication is to efficiently represent sets of characters in bracket expressions. The old bitmap representation is replaced by a bitmap for the first 256 characters combined with a vector of individual wide characters, a vector of character ranges (for [A-Z] etc.), and a vector of character classes (for [[:alpha:]] etc.). One other point of interest is that although the Boyer-Moore algorithm had to be disabled in the general multibyte case, it is still enabled for UTF-8 because of its self-synchronizing nature. This greatly speeds up matching by reducing the number of multibyte conversions that need to be done.
* Remove incomplete support for multi-character collating elements. Removetjr2004-07-111-245/+8
| | | | unused character category calculations.
* Eliminate 61 warnings emitted at WARNS=2 (leaving 53 to go).nectar2003-02-161-2/+2
| | | | | | | Only warnings that could be fixed without changing the generated object code and without restructuring the source code have been handled. Reviewed by: /sbin/md5
* Add restrict type-qualifier.mike2002-10-021-2/+2
|
* Replace various spelling with FALLTHROUGH which is lint()ablecharnier2002-08-251-1/+1
|
* Fix the style of the SCM ID's.obrien2002-03-221-2/+2
| | | | I believe have made all of libc .c's as consistent as possible.
* Remove __P() usage.obrien2002-03-211-43/+43
|
* Remove 'register' keyword.obrien2002-03-211-203/+203
|
* The algorithm that computes the tables used in the BM search algorithm sometimesdcs2001-11-091-1/+2
| | | | | | | | | | access an array beyond it's length. This only happens in the last iteration of a loop, and the value fetched is not used then, so the bug is a relatively innocent one. Fix this by not fetching any value on the last iteration of said loop. Submitted by: MKI <mki@mozone.net> MFC after: 1 week
* altoffset() always returned whenever it recursed, because at the enddcs2000-07-091-0/+4
| | | | | | | | | | | | | | of the processing of the recursion, "scan" would be pointing to O_CH (or O_QUEST), which would then be interpreted as being the end character for altoffset(). We avoid this by properly increasing scan before leaving the switch. Without this, something like (a?b?)?cc would result in a g->moffset of 1 instead of 2. I added a case to the soon-to-be-imported regex(3) test code to catch this error.
* Add some casts here and there.dcs2000-07-091-3/+3
|
* Do not free NULL pointers.dcs2000-07-071-1/+1
|
* Deal with the signed/unsigned chars issue in a more proper manner. Wedcs2000-07-071-3/+5
| | | | | | | | | use a CHAR_MIN-based array, like elsewhere in the code. Remove a number of unused variables (some due to the above change, one that was left after a number of optimizing steps through the source). Brucified by: bde
* I hate signed chars.^W^W^W^W^WCast to unsigned char before using signeddcs2000-07-061-1/+1
| | | | chars as array indices.
* Correct comment to work with test code.dcs2000-07-061-2/+2
| | | | Prevent out of bounds array access in some specific cases.
* Use UCHAR_MAX consistently.dcs2000-07-061-1/+1
|
* Enhance the optimization provided by pre-matching. Fix style bugs withdcs2000-07-021-5/+164
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | previous commits. At the time we search the pattern for the "must" string, we now compute the longest offset from the beginning of the pattern at which the must string might be found. If that offset is found to be infinite (through use of "+" or "*"), we set it to -1 to disable the heuristics applied later. After we are done with pre-matching, we use that offset and the point in the text at which the must string was found to compute the earliest point at which the pattern might be found. Special care should be taken here. The variable "start" is passed to the automata-processing functions fast() and slow() to indicate the point in the text at which they should start working from. The real beginning of the text is passed in a struct match variable m, which is used to check for anchors. That variable, though, is initialized with "start", so we must not adjust "start" before "m" is properly initialized. Simple tests showed a speed increase from 100% to 400%, but they were biased in that regexec() was called for the whole file instead of line by line, and parenthized subexpressions were not searched for. This change adds a single integer to the size of the "guts" structure, and does not change the ABI. Further improvements possible: Since the speed increase observed here is so huge, one intuitive optimization would be to introduce a bias in the function that computes the "must" string so as to prefer a smaller string with a finite offset over a larger one with an infinite offset. Tests have shown this to be a bad idea, though, as the cost of false pre-matches far outweights the benefits of a must offset, even in biased situations. A number of other improvements suggest themselves, though: * identify the cases where the pattern is identical to the must string, and avoid entering fast() and slow() in these cases. * compute the maximum offset from the must string to the end of the pattern, and use that to set the point at which fast() and slow() should give up trying to find a match, and return then return to pre-matching. * return all the way to pre-matching if a "match" was found and later invalidated by back reference processing. Since back references are evil and should be avoided anyway, this is of little use.
* Initialize variables used by the Boyer-Moore algorithm.dcs2000-06-291-0/+2
| | | | | | | This should fix core dumps when the must pattern is of length three or less. Bug found by: knu
* Add Boyler-Moore algorithm to pre-matching test.dcs2000-06-291-0/+144
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The BM algorithm works by scanning the pattern from right to left, and jumping as many characters as viable based on the text's mismatched character and the pattern's already matched suffix. This typically enable us to test only a fraction of the text's characters, but has a worse performance than the straight-forward method for small patterns. Because of this, the BM algorithm will only be used if the pattern size is at least 4 characters. Notice that this pre-matching is done on the largest substring of the regular expression that _must_ be present on the text for a succesful match to be possible at all. For instance, "(xyzzy|grues)" will yield a null "must" substring, and, therefore, not benefit from the BM algorithm at all. Because of the lack of intelligence of the algorithm that finds the "must" string, things like "charjump|matchjump" will also yield a null string. To optimize that, "(char|match)jump" should be used. The setup time (at regcomp()) for the BM algorithm will most likely outweight any benefits for one-time matches. Given the slow regex(3) we have, this is unlikely to be even perceptible, though. The size of a regex_t structure is increased by 2*sizeof(char*) + 256*sizeof(int) + strlen(must)*sizeof(int). This is all inside the regex_t's "guts", which is allocated dynamically by regcomp(). If allocation of either of the two tables fail, the other one is freed. In this case, the straight-forward algorithm is used for pre-matching. Tests exercising the code path affected have shown a speed increase of 50% for "must" strings of length four or five. API and ABI remain unchanged by this commit. The patch submitted on the PR was not used, as it was non-functional. PR: 14342
* unsigned char cleanupache1999-07-261-17/+17
| | | | | | | fix wrong index from p_simp_re() PR: 8790 Submitted by: Alexander Viro <viro@math.psu.edu> (partially)
* Replace memory leaking instances of realloc with non-leaking reallocf.imp1998-09-161-4/+4
| | | | | | | | | | | In some cases replace if (a == null) a = malloc(x); else a = realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is guaranteed to be the same thing. I've been running these on my system here w/o ill effects for some time. However, the CTM-express is at part 6 of 34 for the CAM changes, so I've not been able to do a build world with the CAM in the tree with these changes. Shouldn't impact anything, but...
* Speedup in case locale not usedache1997-04-041-5/+11
|
* collate_range_cmp -> __collate_range_cmpache1996-10-311-4/+5
|
* Convert to newly aded collate compare functionache1996-08-121-4/+4
|
* Remove static collcmp, use new internal function nowache1996-08-121-37/+4
|
OpenPOWER on IntegriCloud