]> mj.ucw.cz Git - xsv.git/commitdiff
Avoid infinite loops when regex matches an empty string
authorMartin Mares <mj@ucw.cz>
Tue, 24 Jul 2012 16:51:27 +0000 (18:51 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 24 Jul 2012 16:51:27 +0000 (18:51 +0200)
xsv.c

diff --git a/xsv.c b/xsv.c
index 545a39efe3e4a98421e201a5d719902bf89ca5e6..04933129a0253984cd3e57fda234fb0bfa60c69f 100644 (file)
--- a/xsv.c
+++ b/xsv.c
@@ -416,6 +416,12 @@ static int regex_read(struct format *fmt)
                        }
                        return 1;
                }
+               if (ovec[0] == ovec[1]) {
+                       warn(fmt, "Regular expression matched an empty separator");
+                       new_field(i);
+                       in_field->len = n - i;
+                       return 1;
+               }
                if (!fmt->sloppy || ovec[0]) {
                        new_field(i);
                        in_field->len = ovec[0] - i;