debianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change
on this file since 8e5935d was
554a2b8,
checked in by Anders Kaseorg <andersk@mit.edu>, 16 years ago
|
Fix format string injection bugs.
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[7d4fbcd] | 1 | #include <string.h> |
---|
| 2 | #include "owl.h" |
---|
| 3 | |
---|
[1aee7d9] | 4 | static const char fileIdent[] = "$Id$"; |
---|
| 5 | |
---|
[e187445] | 6 | void owl_regex_init(owl_regex *re) |
---|
| 7 | { |
---|
[7d4fbcd] | 8 | re->negate=0; |
---|
| 9 | re->string=NULL; |
---|
| 10 | } |
---|
| 11 | |
---|
[e187445] | 12 | int owl_regex_create(owl_regex *re, char *string) |
---|
| 13 | { |
---|
[7d4fbcd] | 14 | int ret; |
---|
[554a2b8] | 15 | char buff1[LINE]; |
---|
[7d4fbcd] | 16 | char *ptr; |
---|
| 17 | |
---|
| 18 | re->string=owl_strdup(string); |
---|
| 19 | |
---|
| 20 | ptr=string; |
---|
| 21 | re->negate=0; |
---|
| 22 | if (string[0]=='!') { |
---|
| 23 | ptr++; |
---|
| 24 | re->negate=1; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | /* set the regex */ |
---|
| 28 | ret=regcomp(&(re->re), ptr, REG_EXTENDED|REG_ICASE); |
---|
| 29 | if (ret) { |
---|
| 30 | regerror(ret, NULL, buff1, LINE); |
---|
[554a2b8] | 31 | owl_function_makemsg("Error in regular expression: %s", buff1); |
---|
[7d4fbcd] | 32 | owl_free(re->string); |
---|
[a6560fe] | 33 | re->string=NULL; |
---|
[7d4fbcd] | 34 | return(-1); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | return(0); |
---|
| 38 | } |
---|
| 39 | |
---|
[bc08664] | 40 | int owl_regex_create_quoted(owl_regex *re, char *string) |
---|
| 41 | { |
---|
| 42 | char *quoted; |
---|
| 43 | |
---|
| 44 | quoted=owl_text_quote(string, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 45 | owl_regex_create(re, quoted); |
---|
| 46 | owl_free(quoted); |
---|
| 47 | return(0); |
---|
| 48 | } |
---|
| 49 | |
---|
[e187445] | 50 | int owl_regex_compare(owl_regex *re, char *string) |
---|
| 51 | { |
---|
[7d4fbcd] | 52 | int out, ret; |
---|
| 53 | |
---|
| 54 | /* if the regex is not set we match */ |
---|
| 55 | if (!owl_regex_is_set(re)) { |
---|
| 56 | return(0); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ret=regexec(&(re->re), string, 0, NULL, 0); |
---|
| 60 | out=ret; |
---|
| 61 | if (re->negate) { |
---|
| 62 | out=!out; |
---|
| 63 | } |
---|
| 64 | return(out); |
---|
| 65 | } |
---|
| 66 | |
---|
[e187445] | 67 | int owl_regex_is_set(owl_regex *re) |
---|
| 68 | { |
---|
[7d4fbcd] | 69 | if (re->string) return(1); |
---|
| 70 | return(0); |
---|
| 71 | } |
---|
| 72 | |
---|
[e187445] | 73 | char *owl_regex_get_string(owl_regex *re) |
---|
| 74 | { |
---|
[7d4fbcd] | 75 | return(re->string); |
---|
| 76 | } |
---|
| 77 | |
---|
[e187445] | 78 | void owl_regex_copy(owl_regex *a, owl_regex *b) |
---|
| 79 | { |
---|
[7d4fbcd] | 80 | b->negate=a->negate; |
---|
| 81 | b->string=owl_strdup(a->string); |
---|
| 82 | memcpy(&(b->re), &(a->re), sizeof(regex_t)); |
---|
| 83 | } |
---|
| 84 | |
---|
[e187445] | 85 | void owl_regex_free(owl_regex *re) |
---|
| 86 | { |
---|
[cb769bb] | 87 | if (re->string) { |
---|
| 88 | owl_free(re->string); |
---|
| 89 | regfree(&(re->re)); |
---|
| 90 | } |
---|
[7d4fbcd] | 91 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.