From nobody Thu Oct 2 08:20:48 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ccl9X2Xb7z69KXD; Thu, 02 Oct 2025 08:20:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ccl9X1kcwz4MtS; Thu, 02 Oct 2025 08:20:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759393248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mPFUf1dClAPpWArnFlhSb1qSNlyYbLZ4PBpRNZ84ius=; b=R7TaJ9efCEpNRTR41eQE25mm+XmADr4FeiLx8dvNolJq2MjWuQY1TPuLWUgk90FBFSmo7Z N9jWvFXGK4CwGricETRarO7Dax+yMuJCWFwqN6HDFV4cs0O4hCfyULaKTZq/ouUmOTB5ga NSsZP6hq9YBJtUDk6HCEHPTE2DVJRjPys0/wd+9z88AxjvUx2iVnC+no7YwsEf8wECWgcu MsqoPdsP39aXoqnqdRphpYBT4VxZWeI50nLwcFD0glU/sdaaClcb5Uf4eiaPt7V+PAhPJP 0CLZ1+yqk2Le9jihzR0w0cycGwpsIruOoO9AI71UZ5T1lYlIRKeARU9qnwug/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759393248; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mPFUf1dClAPpWArnFlhSb1qSNlyYbLZ4PBpRNZ84ius=; b=QYLYbGjD3HDL+/gkF2N5dcTzIszuid+ZeBzNuuDUKr0Nw3TRBnUghAHD/00g2edfH73VXa qiiDS9mIn/2jhiCLPjR3j8AQSwDfFsFrERPiiWMoZON8tXhKa2U54kypz4AYy/vpn3zu2f 2HuMKwZaJOLSZuIrRRLyEwBFj4lut7qM4WgAYivb85U2U9+KztxayXXvislt2DD6QUIeZt DExww13cBNqWNT14WhunY4QcXUV6CwD5P/P7yTFFfuzBIWz7qI/bq2wvBqB2vXClUJYOgy TAIzMqRkCK1QaoQyjpXbx0mznmwM4cvrxjPNVE1SpWEIceyrBm1PWFc1V2wi8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759393248; a=rsa-sha256; cv=none; b=H9anCxE0RdUThzzmtOezA0EvljyaNVO9fq9aLjU0qb/B6k/HkjT9gjpSi1ZIXSMqeh8WY/ E7t263/QjjCfX+A5SnSsYtrYnsopdWfjDq4fcoXEe6YvRmFPf8PHfEzmLFQN+ui/5qaYQW PpSgZkJDpBRIGBtO8Z0EHJuUoaCQNidDPj/AuE6NRBrudXCs61VWmS4yf9SVvacyUBtodf hDUNvHm/vscbUEPjLPP+vL4KD4+FgKqdEbvR3TI6WxsgDjqN+MGaw8jOcyDcvIN3OkHbxg ELxl8Y7msHBQRucRsiZkn40iuRZY2GWgQECh1cVF4XAxZmcYxbdNeVMoY5pzZg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ccl9X1Jkkz10j3; Thu, 02 Oct 2025 08:20:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5928Kmdg023318; Thu, 2 Oct 2025 08:20:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5928KmB2023315; Thu, 2 Oct 2025 08:20:48 GMT (envelope-from git) Date: Thu, 2 Oct 2025 08:20:48 GMT Message-Id: <202510020820.5928KmB2023315@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 073895078ef1 - stable/15 - libucl: Fix bugs in C-style comment parser List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 073895078ef1b73a461acaf2eaa3776929279047 Auto-Submitted: auto-generated The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=073895078ef1b73a461acaf2eaa3776929279047 commit 073895078ef1b73a461acaf2eaa3776929279047 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-01 09:28:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-02 08:19:24 +0000 libucl: Fix bugs in C-style comment parser When an asterisk is encountered inside a C-style comment, we first check if there is at least one more character left in the buffer, and if that character is a slash, which would terminate the comment. If that is not the case, the next two characters are consumed without being inspected. If one of those is a double quote, or the initial asterisk of an asterisk-slash pair, we end up misparsing the comment. MFC after: 3 days Reviewed by: kevans, bofh Differential Revision: https://reviews.freebsd.org/D52808 (cherry picked from commit b5e2bd5ef38181ce4a445ec19f1fa5cb6c8ea692) --- contrib/libucl/src/ucl_parser.c | 77 ++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/contrib/libucl/src/ucl_parser.c b/contrib/libucl/src/ucl_parser.c index 6be16d12169c..728cd6381056 100644 --- a/contrib/libucl/src/ucl_parser.c +++ b/contrib/libucl/src/ucl_parser.c @@ -164,51 +164,50 @@ start: } } } - else if (chunk->remain >= 2 && *p == '/') { - if (p[1] == '*') { - beg = p; - ucl_chunk_skipc (chunk, p); - comments_nested ++; - ucl_chunk_skipc (chunk, p); - - while (p < chunk->end) { - if (*p == '"' && *(p - 1) != '\\') { - quoted = !quoted; - } - - if (!quoted) { - if (*p == '*') { - ucl_chunk_skipc (chunk, p); - if (chunk->remain > 0 && *p == '/') { - comments_nested --; - if (comments_nested == 0) { - if (parser->flags & UCL_PARSER_SAVE_COMMENTS) { - ucl_save_comment (parser, beg, p - beg + 1); - beg = NULL; - } - - ucl_chunk_skipc (chunk, p); - goto start; - } - } - ucl_chunk_skipc (chunk, p); - } - else if (p[0] == '/' && chunk->remain >= 2 && p[1] == '*') { - comments_nested ++; - ucl_chunk_skipc (chunk, p); - ucl_chunk_skipc (chunk, p); - continue; + else if (chunk->remain >= 2 && *p == '/' && p[1] == '*') { + beg = p; + comments_nested ++; + ucl_chunk_skipc (chunk, p); + ucl_chunk_skipc (chunk, p); + while (p < chunk->end) { + if (*p == '"' && *(p - 1) != '\\') { + /* begin or end double-quoted string */ + quoted = !quoted; + ucl_chunk_skipc (chunk, p); + } + else if (quoted) { + /* quoted character */ + ucl_chunk_skipc (chunk, p); + } + else if (chunk->remain >= 2 && *p == '*' && p[1] == '/') { + /* end of comment */ + ucl_chunk_skipc (chunk, p); + ucl_chunk_skipc (chunk, p); + comments_nested --; + if (comments_nested == 0) { + if (parser->flags & UCL_PARSER_SAVE_COMMENTS) { + ucl_save_comment (parser, beg, p - beg + 1); + beg = NULL; } + goto start; } - + } + else if (chunk->remain >= 2 && *p == '/' && p[1] == '*') { + /* start of nested comment */ + comments_nested ++; + ucl_chunk_skipc (chunk, p); ucl_chunk_skipc (chunk, p); } - if (comments_nested != 0) { - ucl_set_err (parser, UCL_ENESTED, - "unfinished multiline comment", &parser->err); - return false; + else { + /* anything else */ + ucl_chunk_skipc (chunk, p); } } + if (comments_nested != 0) { + ucl_set_err (parser, UCL_ENESTED, + "unfinished multiline comment", &parser->err); + return false; + } } if (beg && p > beg && (parser->flags & UCL_PARSER_SAVE_COMMENTS)) {