]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Fixup readline
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Feb 2021 16:51:40 +0000 (16:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 25 Feb 2021 16:51:40 +0000 (16:51 +0000)
This could read into the next line when a line was empty

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/util.h
src/libpakfire/parser/scanner.l
src/libpakfire/util.c

index 83700d5a8fc5222caff378006ee20c8aab7ab388..4022190e8fec46883cf8e73ba7783087d871a46b 100644 (file)
@@ -56,6 +56,7 @@ void pakfire_partition_string(const char* s, const char* delim, char** s1, char*
 #ifdef PAKFIRE_PRIVATE
 
 int pakfire_string_endswith(const char* s, const char* suffix);
+char* pakfire_lstrip(const char* s);
 
 #endif
 
index 71715a087a722a3b3407dc5153ce17a84278e5df..b2fd90d60e65cf3c524fa906bc491a5af668c108 100644 (file)
@@ -37,6 +37,7 @@ int num_lines;
 #include <stdlib.h>
 
 #include <pakfire/parser.h>
+#include <pakfire/util.h>
 
 #include "grammar.h"
 
@@ -210,15 +211,12 @@ scriptlet                         script(let)?
                                                        yy_push_state(NOKEYWORD);
                                                }
 
-<READLINE>{whitespace} {
-                                                       // consume any leading whitespace
-                                               }
-<READLINE>[^ \t].*$            {
+<READLINE>.*$                  {
                                                        // Return to caller
                                                        yy_pop_state();
 
                                                        // Copy the entire string
-                                                       yylval.string = strdup(yytext);
+                                                       yylval.string = pakfire_lstrip(yytext);
 
                                                        return T_STRING;
                                                }
index 38c0a71ba758f9e8f6c7766f0ebf0a59294ef517..e4eac58fb7782f5e6fc16381897290112db3e3c0 100644 (file)
@@ -43,6 +43,16 @@ int pakfire_string_endswith(const char* s, const char* suffix) {
        return !strcmp(s + strlen(s) - strlen(suffix), suffix);
 }
 
+char* pakfire_lstrip(const char* s) {
+       while (*s && isspace(*s))
+               s++;
+
+       if (s)
+               return strdup(s);
+
+       return NULL;
+}
+
 char* pakfire_format_size(double size) {
        char string[STRING_SIZE];
        const char* units[] = {" ", "k", "M", "G", "T", NULL};