[augeas-devel] augeas: master - * src/fa.c: test for invalid ranges like [z-a]

David Lutterkort lutter at fedoraproject.org
Wed Feb 11 21:43:21 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=007908c4f17eb319055dd428f807d2e05412557e
Commit:        007908c4f17eb319055dd428f807d2e05412557e
Parent:        e27190fbc420aafe7e969e40199affec4b80e488
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Feb 11 11:25:30 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Feb 11 11:25:30 2009 -0800

* src/fa.c: test for invalid ranges like [z-a]

---
 src/fa.c       |    8 ++++++++
 tests/fatest.c |    5 +++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/fa.c b/src/fa.c
index ed528c5..f9d3258 100644
--- a/src/fa.c
+++ b/src/fa.c
@@ -2544,6 +2544,10 @@ static void parse_char_class(const char **regexp, struct re *re,
             goto error;
         }
         if (peek(regexp, "]")) {
+            if (from > to) {
+                *error = REG_ERANGE;
+                goto error;
+            }
             add_re_char(re, from, to);
             add_re_char(re, '-', '-');
             return;
@@ -2551,6 +2555,10 @@ static void parse_char_class(const char **regexp, struct re *re,
             to = parse_char(regexp, 0);
         }
     }
+    if (from > to) {
+        *error = REG_ERANGE;
+        goto error;
+    }
     add_re_char(re, from, to);
  error:
     return;
diff --git a/tests/fatest.c b/tests/fatest.c
index a226ef0..c733ba0 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -418,6 +418,10 @@ static void testAsRegexpMinus(CuTest *tc) {
     free(re);
 }
 
+static void testRangeEnd(CuTest *tc) {
+    make_fa(tc, "[1-0]", REG_ERANGE);
+}
+
 int main(int argc, char **argv) {
     if (argc == 1) {
         char *output = NULL;
@@ -436,6 +440,7 @@ int main(int argc, char **argv) {
         SUITE_ADD_TEST(suite, testAmbig);
         SUITE_ADD_TEST(suite, testAsRegexp);
         SUITE_ADD_TEST(suite, testAsRegexpMinus);
+        SUITE_ADD_TEST(suite, testRangeEnd);
 
         CuSuiteRun(suite);
         CuSuiteSummary(suite, &output);




More information about the augeas-devel mailing list