checkpolicy: Allow lineno > 1 for source file line
PATCH v2 1/1 checkpolicy: Allow lineno > 1 for source file line
There are cases that the line number starts with a number greater than one, if preprocessor skipped the very first line. This extends #line syntax so any lineno is valid for lines with a source file path.
Changes since v1:
- Leave set_source_file as-is to prevent regressions
--- checkpolicy/policy_scan.l | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
checkpolicy/policy_scan.l +20 -1
@@ -57,6 +57,7 @@ void yyfatal(const char *msg) #endif void set_source_file(const char *name); +static void set_source_line_and_file(const char *line); char source_file[PATH_MAX]; unsigned long source_lineno = 1;
@@ -297,7 +298,7 @@ GLBLUB { return(GLBLUB); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])* { return(IPV6_ADDR); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])*"/"{digit}{1,3} { return(IPV6_CIDR); } {digit}+(\.({alnum}|[_.])*)? { return(VERSION_IDENTIFIER); } -#line[ ]1[ ]\"[^\n]*\" { set_source_file(yytext+9); } +#line[ ]{digit}+[ ]\"[^\n]*\" { set_source_line_and_file(yytext+6); } #line[ ]{digit}+ { errno = 0; source_lineno = strtoul(yytext+6, NULL, 10) - 1;
@@ -395,3 +396,21 @@ void set_source_file(const char *name) if (strlen(source_file) && source_file[strlen(source_file)-1] == '"') source_file[strlen(source_file)-1] = '\0'; } + +void set_source_line_and_file(const char *line) +{ + char *name; + unsigned long lineno; + errno = 0; + lineno = strtoul(line, &name, 10) - 1; + if (errno) { + yywarn("source line number too big"); + } + set_source_file(name + 2 /* skip a space and a quote */ ); + + /* + * set_source_file sets source_lineno to 1. + * Assign source_lineno after calling set_source_file. + */ + source_lineno = lineno; +}
Signature · 1 line
2.49.0.901.g37484f566f-goog
Quoted 7 lines · Inseob Kim
There are cases that the line number starts with a number greater than one, if preprocessor skipped the very first line. This extends #line syntax so any lineno is valid for lines with a source file path.
Signed-off-by Inseob Kim <[email protected]>
Quoted 53 lines
Changes since v1:
- Leaveset_source_fileas-is to prevent regressions--- checkpolicy/policy_scan.l | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)checkpolicy/policy_scan.l +20
-2@@ -57,6 +57,7 @@ void yyfatal(const char *msg) #endif void set_source_file(const char *name); +static void set_source_line_and_file(const char *line); char source_file[PATH_MAX]; unsigned long source_lineno = 1;@@ -297,7 +298,7 @@ GLBLUB { return(GLBLUB); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])* { return(IPV6_ADDR); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])*"/"{digit}{1,3} { return(IPV6_CIDR); } {digit}+(\.({alnum}|[_.])*)? { return(VERSION_IDENTIFIER); } -#line[ ]1[ ]\"[^\n]*\" { set_source_file(yytext+9); } +#line[ ]{digit}+[ ]\"[^\n]*\" { set_source_line_and_file(yytext+6); } #line[ ]{digit}+ { errno = 0; source_lineno = strtoul(yytext+6, NULL, 10) - 1;@@ -395,3 +396,21 @@ void set_source_file(const char *name) if (strlen(source_file) && source_file[strlen(source_file)-1] == '"') source_file[strlen(source_file)-1] = '\0'; } + +void set_source_line_and_file(const char *line) +{ + char *name; + unsigned long lineno; + errno = 0; + lineno = strtoul(line, &name, 10) - 1; + if (errno) { + yywarn("source line number too big"); + } + set_source_file(name + 2 /* skip a space and a quote */ ); + + /* + * set_source_file sets source_lineno to 1. + * Assign source_lineno after calling set_source_file. + */ + source_lineno = lineno; +} --2.49.0.901.g37484f566f-goog
Quoted 12 lines · James Carter
Quoted 7 lines · Inseob Kim
There are cases that the line number starts with a number greater than one, if preprocessor skipped the very first line. This extends #line syntax so any lineno is valid for lines with a source file path.
Signed-off-by Inseob Kim <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 53 lines
Quoted 53 lines
Changes since v1:
- Leaveset_source_fileas-is to prevent regressions--- checkpolicy/policy_scan.l | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)checkpolicy/policy_scan.l +20
-2@@ -57,6 +57,7 @@ void yyfatal(const char *msg) #endif void set_source_file(const char *name); +static void set_source_line_and_file(const char *line); char source_file[PATH_MAX]; unsigned long source_lineno = 1;@@ -297,7 +298,7 @@ GLBLUB { return(GLBLUB); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])* { return(IPV6_ADDR); } {hexval}{0,4}":"{hexval}{0,4}":"({hexval}|[:.])*"/"{digit}{1,3} { return(IPV6_CIDR); } {digit}+(\.({alnum}|[_.])*)? { return(VERSION_IDENTIFIER); } -#line[ ]1[ ]\"[^\n]*\" { set_source_file(yytext+9); } +#line[ ]{digit}+[ ]\"[^\n]*\" { set_source_line_and_file(yytext+6); } #line[ ]{digit}+ { errno = 0; source_lineno = strtoul(yytext+6, NULL, 10) - 1;@@ -395,3 +396,21 @@ void set_source_file(const char *name) if (strlen(source_file) && source_file[strlen(source_file)-1] == '"') source_file[strlen(source_file)-1] = '\0'; } + +void set_source_line_and_file(const char *line) +{ + char *name; + unsigned long lineno; + errno = 0; + lineno = strtoul(line, &name, 10) - 1; + if (errno) { + yywarn("source line number too big"); + } + set_source_file(name + 2 /* skip a space and a quote */ ); + + /* + * set_source_file sets source_lineno to 1. + * Assign source_lineno after calling set_source_file. + */ + source_lineno = lineno; +} --2.49.0.901.g37484f566f-goog