From f2f1071b16f0c74edc0e89ffe7b0c01636c54c4f Mon Sep 17 00:00:00 2001 From: oes Date: Wed, 23 May 2001 10:39:05 +0000 Subject: [PATCH] - Added support for escaping the comment character in config files by a backslash - Added support for line continuation in config files - Fixed a buffer overflow bug with long config lines --- config | 10 +++++++--- loaders.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/config b/config index 9a20fb7e..520ad092 100644 --- a/config +++ b/config @@ -1,7 +1,7 @@ # Sample Configuration file for the Internet Junkbuster 2.0 # -# $Id: config,v 1.3 2001/05/20 01:21:20 jongfoster Exp $ +# $Id: config,v 1.4 2001/05/22 17:43:35 oes Exp $ # # Table of Contents @@ -33,8 +33,8 @@ # # Indicates that the blockfile is named 'blocklist.ini'. # -# The '#' indicates a comment. Any part of a line following a # is -# ignored. +# The '#' indicates a comment. Any part of a line following a '#' is +# ignored, except if the '#' is preceded by a '\'. # # Thus, by placing a # at the start of an existing configuration line, # you can make it a comment and it will be treated as if it weren't there. @@ -42,6 +42,10 @@ # off features: If you comment out the "logfile" line, junkbuster will # not log at all. Watch for the "default:" section in each explanation # to see what happens if the option is left unset (or commented out). +# +# Long lines can be continued on the next line by using a `\' as +# the last character. This also works if comments are present in +# between. # # diff --git a/loaders.c b/loaders.c index 4c218510..a485d935 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.3 2001/05/20 01:21:20 jongfoster Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.4 2001/05/22 18:56:28 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -35,6 +35,9 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.3 2001/05/20 01:21:20 jongfoster * * Revisions : * $Log: loaders.c,v $ + * Revision 1.4 2001/05/22 18:56:28 oes + * CRLF -> LF + * * Revision 1.3 2001/05/20 01:21:20 jongfoster * Version 2.9.4 checkin. * - Merged popupfile and cookiefile, and added control over PCRS @@ -709,8 +712,9 @@ static int check_file_changed(const struct file_list * current, * Function : read_config_line * * Description : Read a single non-empty line from a file and return - * it. Trims comments, leading and trailing whitespace. - * Also wites the file to fs->proxy_args. + * it. Trims comments, leading and trailing whitespace + * and respects escaping of newline and comment char. + * Also writes the file to fs->proxy_args. * * Parameters : * 1 : buf = Buffer to use. @@ -727,6 +731,9 @@ char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs) { char *p, *q; char linebuf[BUFSIZ]; + int contflag = 0; + + *buf = '\0'; while (fgets(linebuf, sizeof(linebuf), fp)) { @@ -743,17 +750,40 @@ char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs) } #endif /* ndef SPLIT_PROXY_ARGS */ - /* Trim off newline and any comment */ - if ((p = strpbrk(linebuf, "\r\n#")) != NULL) + /* Trim off newline */ + if ((p = strpbrk(linebuf, "\r\n")) != NULL) { *p = '\0'; } + + /* Line continuation? Trim escape and set flag. */ + if ((p != linebuf) && (*--p == '\\')) + { + contflag = 1; + *p = '\0'; + } + + /* If there's a comment char.. */ + if ((p = strpbrk(linebuf, "#")) != NULL) + { + /* ..and it's escaped, left-shift the line over the escape. */ + if ((p != linebuf) && (*(p-1) == '\\')) + { + q = p-1; + while ((*q++ = *p++) != '\0') /* nop */; + } + /* Else, chop off the rest of the line */ + else + { + *p = '\0'; + } + } /* Trim leading whitespace */ p = linebuf; while (*p && ijb_isspace(*p)) { - *p++; + p++; } if (*p) @@ -788,8 +818,16 @@ char *read_config_line(char *buf, int buflen, FILE *fp, struct file_list *fs) /* More paranoia. This if statement is always true. */ if (*linebuf) { - strcpy(buf, linebuf); - return buf; + strncat(buf, linebuf, buflen - strlen(buf)); + if (contflag) + { + contflag = 0; + continue; + } + else + { + return buf; + } } } } -- 2.39.2