From nobody Wed Oct 01 09:39:10 2025 X-Original-To: dev-commits-src-main@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 4cc8yR0TDzz69Gd6; Wed, 01 Oct 2025 09:39:11 +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 4cc8yQ3qkPz3HSl; Wed, 01 Oct 2025 09:39:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759311550; 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=7+boV47q/mJNB9vIY77QXtElUtcI3YSS1IZZYt/YRL8=; b=Keg7+BdBoLcItQDkREjzsal2brnew0UkgoMHE5J4sx+HU/ap/XDgAT6ncnZO44axg3VHQl Nq7DbAFUIhEyG9DRsy4GdIVxaVOQVRo7aRUyJBE2iOjEd1FtEh4UaERZvERu8Q9eb/X6zC aEI9rZ5288qWGyUit3KOL4d80kthLynJxPAVvDzqE+q85avrO4XEljmG9d7v2dPiVNiIJ3 Ids9r7og+hZA4Fc96ivYwCL6TyZds9/sYddEhlB/uR85KidL8Eg1NHHHvpi521n9vbSv52 VxEXMGv7xqba7MdcSYElG5ZfOFo2mjG5GYKyNOEfmo1xVaMHNJffoIexuVUViQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759311550; 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=7+boV47q/mJNB9vIY77QXtElUtcI3YSS1IZZYt/YRL8=; b=wqRdDdz0FrrQe5bwdl4rTBaXPmY9TOzUKfHyO+bx3f723SACqkKKgfj279lD0qgUQR8gfS FS6EzCkPxvId/042KSYUtfKbCXNJ6Ec2U0NSA4Rz/2X7nukWlObTIjcyeaTt0vYIrY2cMn cbKJj3p87vT4irC8dD7FSMuqwIfzW7XsGHAv3qKO22dGvptaK/UAnd3H4KAtWJTCTMtH6J CB8nkYqLkObRQ4z9NGj9cop/Y0M1D52y9/6Tz40L1a2Z6czVPzR6/IpBlRygc7Lr7vsgg1 zDSu7g4aC/W9GjYamZfVcyV9MhOqPJ2DLpQewKRH/KJdLgtTH8bpf7VmompZSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759311550; a=rsa-sha256; cv=none; b=ZxZERUKo9oXTuxYXphMuRlovg1nwGB0e+uzgmv2rn2cX7qtFxS05MDT7BQoApal3ffTE25 lVZuFrFA6ikwBxSXO8nvTr6I+6uADaIGEJGXuxIm0yd/jZuW+0N2YUMin2CybdWpmkm+GX u+zRYP+YSb92/vllWzIDNFGJTX5GKhvE3UTH46jaPQETod3eLTwCgC+5WIS2gmqg9Xu3aS 2MIB8+CLe/YA3renLC69ImLmGhzq4Pb1qDvEGrbbGXzqokIv+uRxH7Kuf5dc/1ORSpkS0x O4nlY9zgGh3L6buWzPKvjCd3wz/9AHitRcINkbkF7+7OGjPGhtF5uWs1SSmLDA== 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 4cc8yQ3N1Qz2JK; Wed, 01 Oct 2025 09:39:10 +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 5919dAAr017248; Wed, 1 Oct 2025 09:39:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5919dABY017245; Wed, 1 Oct 2025 09:39:10 GMT (envelope-from git) Date: Wed, 1 Oct 2025 09:39:10 GMT Message-Id: <202510010939.5919dABY017245@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: b5e2bd5ef381 - main - libucl: Fix bugs in C-style comment parser List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b5e2bd5ef38181ce4a445ec19f1fa5cb6c8ea692 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b5e2bd5ef38181ce4a445ec19f1fa5cb6c8ea692 commit b5e2bd5ef38181ce4a445ec19f1fa5cb6c8ea692 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-01 09:28:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-01 09:28:56 +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 --- 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)) {