Re: [PATCH v2 1/2] CLEANUP: ssl: Use structured format for error line report during crt-list parsing

2020-10-02 Thread William Lallemand
On Tue, Sep 29, 2020 at 06:00:27PM +0200, Tim Duesterhus wrote:
> This reuses the known `parsing [%s:%d]:` from regular config file error
> reporting.
 

On Tue, Sep 29, 2020 at 06:00:28PM +0200, Tim Duesterhus wrote:
> Similar to warning during the parsing of the regular configuration file
> that was added in 2fd5bdb439da29f15381aeb57c51327ba57674fc this patch adds
> a warning to the parsing of a crt-list if the file does not end in a
> newline (and thus might have been truncated).
> 
> The logic essentially just was copied over. It might be good to refactor
> this in the future, allowing easy re-use within all line-based config
> parsers.
> 
> see https://github.com/haproxy/haproxy/issues/860#issuecomment-693422936
> see 0354b658f061d00d5ab4b728d7deeff2c8f1503a
> 
> This should be backported as a warning to 2.2.

Thanks, both merged.


-- 
William Lallemand



[PATCH v2 1/2] CLEANUP: ssl: Use structured format for error line report during crt-list parsing

2020-09-29 Thread Tim Duesterhus
This reuses the known `parsing [%s:%d]:` from regular config file error
reporting.
---
 src/ssl_crtlist.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/ssl_crtlist.c b/src/ssl_crtlist.c
index fd141fc50..f1c15e051 100644
--- a/src/ssl_crtlist.c
+++ b/src/ssl_crtlist.c
@@ -327,8 +327,8 @@ int crtlist_parse_line(char *line, char **crt_path, struct 
crtlist_entry *entry,
/* Check if we reached the limit and the last char is not \n.
 * Watch out for the last line without the terminating '\n'!
 */
-   memprintf(err, "line %d too long in file '%s', limit is %d 
characters",
- linenum, file, CRT_LINESIZE-1);
+   memprintf(err, "parsing [%s:%d]: line too longlimit is %d 
characters",
+ file, linenum, CRT_LINESIZE-1);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -340,12 +340,12 @@ int crtlist_parse_line(char *line, char **crt_path, 
struct crtlist_entry *entry,
*line = 0;
} else if (*line == '[') {
if (ssl_b) {
-   memprintf(err, "too many '[' on line %d in file 
'%s'.", linenum, file);
+   memprintf(err, "parsing [%s:%d]: too many '['", 
file, linenum);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
if (!arg) {
-   memprintf(err, "file must start with a cert on 
line %d in file '%s'", linenum, file);
+   memprintf(err, "parsing [%s:%d]: file must 
start with a cert", file, linenum);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -354,12 +354,12 @@ int crtlist_parse_line(char *line, char **crt_path, 
struct crtlist_entry *entry,
*line = 0;
} else if (*line == ']') {
if (ssl_e) {
-   memprintf(err, "too many ']' on line %d in file 
'%s'.", linenum, file);
+   memprintf(err, "parsing [%s:%d]: too many ']'", 
file, linenum);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
if (!ssl_b) {
-   memprintf(err, "missing '[' in line %d in file 
'%s'.", linenum, file);
+   memprintf(err, "parsing [%s:%d]: missing '['", 
file, linenum);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -368,7 +368,7 @@ int crtlist_parse_line(char *line, char **crt_path, struct 
crtlist_entry *entry,
*line = 0;
} else if (newarg) {
if (arg == MAX_CRT_ARGS) {
-   memprintf(err, "too many args on line %d in 
file '%s'.", linenum, file);
+   memprintf(err, "parsing [%s:%d]: too many args 
", file, linenum);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -403,8 +403,8 @@ int crtlist_parse_line(char *line, char **crt_path, struct 
crtlist_entry *entry,
newarg = 1;
cfgerr |= ssl_bind_kws[i].parse(args, cur_arg, 
NULL, ssl_conf, err);
if (cur_arg + 1 + ssl_bind_kws[i].skip > ssl_e) 
{
-   memprintf(err, "ssl args out of '[]' 
for %s on line %d in file '%s'",
- args[cur_arg], linenum, file);
+   memprintf(err, "parsing [%s:%d]: ssl 
args out of '[]' for %s",
+ file, linenum, args[cur_arg]);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -413,8 +413,8 @@ int crtlist_parse_line(char *line, char **crt_path, struct 
crtlist_entry *entry,
}
}
if (!cfgerr && !newarg) {
-   memprintf(err, "unknown ssl keyword %s on line %d in 
file '%s'.",
- args[cur_arg], linenum, file);
+   memprintf(err, "parsing [%s:%d]: unknown ssl keyword 
%s",
+ file, linenum, args[cur_arg]);
cfgerr |= ERR_ALERT | ERR_FATAL;
goto error;
}
@@ -477,8 +477,8 @@ int crtlist_parse_file(char *file, struct bind_conf 
*bind_conf, struct p