From patchwork Sat Sep 19 23:09:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1463 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id YKDVJKMcZ184HQAAIUCqbw (envelope-from ) for ; Sun, 20 Sep 2020 05:10:59 -0400 Received: from proxy19.mail.iad3b.rsapps.net ([172.31.255.6]) by director11.mail.ord1d.rsapps.net with LMTP id 8EOiJKMcZ19vYAAAvGGmqA (envelope-from ) for ; Sun, 20 Sep 2020 05:10:59 -0400 Received: from smtp26.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy19.mail.iad3b.rsapps.net with LMTPS id UFWIHaMcZ1+SdQAAIG4riQ (envelope-from ) for ; Sun, 20 Sep 2020 05:10:59 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp26.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 322b03a0-fb21-11ea-ab35-5254001088d3-1-1 Received: from [216.105.38.7] ([216.105.38.7:40214] helo=lists.sourceforge.net) by smtp26.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id FC/AB-01447-2AC176F5; Sun, 20 Sep 2020 05:10:59 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kJvM5-0003Y8-W3; Sun, 20 Sep 2020 09:09:57 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJvM3-0003Xx-I0 for openvpn-devel@lists.sourceforge.net; Sun, 20 Sep 2020 09:09:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YH7osrOr7fntu4/vzpu+OpmfCfx8ir8ZcC6scrK1aXE=; b=T9Nvk+Ucld9pvpjOoaY7GtLVTn nI/VTBjZAGe2dlG0gHcR4E1IiedF9nBQU6FN5jkFZNJezE71hBXhqji2r10deYIXM4Psans6e+kwv 1/fB1qUrIXqQDXQAN7gT4BGlTbEsmO1NiNzTOhELf0rkZUGIC+MHE7Jhs3kSBGFIyRbc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:To:From: Sender:Reply-To:Cc:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=YH7osrOr7fntu4/vzpu+OpmfCfx8ir8ZcC6scrK1aXE=; b=Q 1HENCbHSS7crua0aFMNaNkDrP9vOpEggyTkuxMR1AQs7rTJa3BhwdIPkHxpXmePYvIyY9NI40yaEy Q0v+ctYRjckE8d6+ZKIReOSQLXeZps9s9RsE12Q2xfv0Zr84D4/Xfl0PCKbSP8Axf1GP1p4D6FSID Q+wK6bUYWGCeMopc=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kJvLw-000DMW-HV for openvpn-devel@lists.sourceforge.net; Sun, 20 Sep 2020 09:09:55 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.15.2/8.14.9) with ESMTP id 08K99Utd008369 for ; Sun, 20 Sep 2020 11:09:30 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.15.2/8.14.9/Submit) id 08K99Uf4008368 for openvpn-devel@lists.sourceforge.net; Sun, 20 Sep 2020 11:09:30 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 20 Sep 2020 11:09:29 +0200 Message-Id: <20200920090929.8321-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: muc.de] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1kJvLw-000DMW-HV Subject: [Openvpn-devel] [PATCH] Fix line number reporting on config file errors after segments X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox segments neglected to increment the "current line number in config file" variable (line_num), so after the first , errors reported have the wrong line number. Fix by introducing an extra argument to the check_inline*() / read_inline_file() call chain: "so many lines in the inline block". Trac: #1325 Signed-off-by: Gert Doering Acked-by: Antonio Quartulli --- src/openvpn/options.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f370a2bb..af517bab 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -4634,7 +4634,8 @@ in_src_get(const struct in_src *is, char *line, const int size) } static char * -read_inline_file(struct in_src *is, const char *close_tag, struct gc_arena *gc) +read_inline_file(struct in_src *is, const char *close_tag, + int *num_lines, struct gc_arena *gc) { char line[OPTION_LINE_SIZE]; struct buffer buf = alloc_buf(8*OPTION_LINE_SIZE); @@ -4643,6 +4644,7 @@ read_inline_file(struct in_src *is, const char *close_tag, struct gc_arena *gc) while (in_src_get(is, line, sizeof(line))) { + (*num_lines)++; char *line_ptr = line; /* Remove leading spaces */ while (isspace(*line_ptr)) @@ -4677,9 +4679,11 @@ read_inline_file(struct in_src *is, const char *close_tag, struct gc_arena *gc) } static bool -check_inline_file(struct in_src *is, char *p[], struct gc_arena *gc) +check_inline_file(struct in_src *is, char *p[], + int *num_lines, struct gc_arena *gc) { bool is_inline = false; + *num_lines = 0; if (p[0] && !p[1]) { @@ -4692,7 +4696,7 @@ check_inline_file(struct in_src *is, char *p[], struct gc_arena *gc) p[0] = string_alloc(arg + 1, gc); close_tag = alloc_buf(strlen(p[0]) + 4); buf_printf(&close_tag, "", p[0]); - p[1] = read_inline_file(is, BSTR(&close_tag), gc); + p[1] = read_inline_file(is, BSTR(&close_tag), num_lines, gc); p[2] = NULL; free_buf(&close_tag); is_inline = true; @@ -4702,22 +4706,23 @@ check_inline_file(struct in_src *is, char *p[], struct gc_arena *gc) } static bool -check_inline_file_via_fp(FILE *fp, char *p[], struct gc_arena *gc) +check_inline_file_via_fp(FILE *fp, char *p[], + int *num_lines, struct gc_arena *gc) { struct in_src is; is.type = IS_TYPE_FP; is.u.fp = fp; - return check_inline_file(&is, p, gc); + return check_inline_file(&is, p, num_lines, gc); } static bool check_inline_file_via_buf(struct buffer *multiline, char *p[], - struct gc_arena *gc) + int *num_lines, struct gc_arena *gc) { struct in_src is; is.type = IS_TYPE_BUF; is.u.multiline = multiline; - return check_inline_file(&is, p, gc); + return check_inline_file(&is, p, num_lines, gc); } static void @@ -4782,12 +4787,15 @@ read_config_file(struct options *options, if (parse_line(line + offset, p, SIZE(p)-1, file, line_num, msglevel, &options->gc)) { bool is_inline; + int lines; bypass_doubledash(&p[0]); - is_inline = check_inline_file_via_fp(fp, p, &options->gc); + is_inline = check_inline_file_via_fp(fp, p, + &lines, &options->gc); add_option(options, p, is_inline, file, line_num, level, msglevel, permission_mask, option_types_found, es); + line_num += lines; } } if (fp != stdin) @@ -4831,11 +4839,14 @@ read_config_string(const char *prefix, if (parse_line(line, p, SIZE(p)-1, prefix, line_num, msglevel, &options->gc)) { bool is_inline; + int lines; bypass_doubledash(&p[0]); - is_inline = check_inline_file_via_buf(&multiline, p, &options->gc); + is_inline = check_inline_file_via_buf(&multiline, p, + &lines, &options->gc); add_option(options, p, is_inline, prefix, line_num, 0, msglevel, permission_mask, option_types_found, es); + line_num += lines; } CLEAR(p); }