From nobody Thu Oct 2 08:20:59 2025 X-Original-To: dev-commits-src-all@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 4ccl9m3zSPz69KqW; Thu, 02 Oct 2025 08:21:00 +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 4ccl9m0wJCz4NXZ; Thu, 02 Oct 2025 08:21:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759393260; 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=RD2QTAX6nXcftQtWwx4jvKyoYZ9+Tx8il/i+W5j1huY=; b=cgZZRYAEWtLaKFEZ2dbKhCow+PRYVVTb66Ap9g3Z+K2eRRWoUpd2SPS/AQlNAS4lALGv5Y WtK9Ex5F/7OEApNTJz7hzArjXFe1Hb/2hOm5ZJCy8wuc+JL1RLo9dfLq0lmBYvPq+N+lUT fE4elCk9nRfXjtiH/Jp9ztHFtbG3Up1xPvw2CBTkT/izjW4WqAD6+Yw8lnI9Naq9Uu9Mqk gMeldZHyTH/VSZD9sFUQsKLNp6j8i5bKQ7i/2FCFU8kUA4ufoSFZZfE5SeeDxK5gjmriJp IQO3VzWf+nkX38Q8o9mziZXxwFx5RotIh9kHmEDqV/7uturFljKqSPMOXalFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1759393260; 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=RD2QTAX6nXcftQtWwx4jvKyoYZ9+Tx8il/i+W5j1huY=; b=jj/TU29//ENDWvgVUmKwRIBnhgeZkd0VzhinUVH1dyBmFh3ZRCaRy0codKNzqs1tKuDxvI uFUb02NNQDaDeTRsiIEj+7Qu+3uaAfBFCjuqqDoZ2hSb8PSL+uXfMaTACsQY/pkp5A/SB5 2QE5HXxMKBM/gUgeQzYa+bqNEfKL2pbfYapmtOOGc+Xf8bhmCRwMlUTiTY4KnT51r2NRBm ogiiyZOrZL5rcWBRQT4iH8lx/+gF0Eij8ZME69Z27cMjqTjxunehUxr1skVKfnWQfBy1AE 2UJOCRCSafbuE3Hd8J0u01BLKihW0gw8i0tBLo5rIYrhBHYsp/A9Q/+lnHEmOQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1759393260; a=rsa-sha256; cv=none; b=cddICl4r5bOS/V79+NHe9ec9GfuF/C0gLeqrZlOEtiul6nF1hkAtl0s50zHc5I1ZNTPpu8 7S4uNt9EIVoSBuyHPPmT8z6baEHu3UbqBA4Y0byRMtOkqm7I1LVDGQv4Ok/F0NDxNQ62H4 1qFHrz/4vy18WjFmQ15tl9hMsPmaBVKrr1gG1XSYQzC8xiR48o/D7KzIe+gYulAYIhSXe9 tNZKHvAiCS6hL31rsF2ZcaUD4Ydinb9nFyPXHSWQLGwvMl5GCpOTBXf7hkO+e6FYvPjbWy +2URqxXzvzSwvxCEnZ0yYKh8iIu58fnSrsJCIWvKY73PspwHEgBWD1jkPWsX2Q== 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 4ccl9m07Ptz10VR; Thu, 02 Oct 2025 08:21:00 +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 5928KxxZ024013; Thu, 2 Oct 2025 08:20:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5928KxZ6024010; Thu, 2 Oct 2025 08:20:59 GMT (envelope-from git) Date: Thu, 2 Oct 2025 08:20:59 GMT Message-Id: <202510020820.5928KxZ6024010@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: 4704cb6d92c0 - stable/13 - libucl: Fix bugs in C-style comment parser List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/13 X-Git-Reftype: branch X-Git-Commit: 4704cb6d92c024c1204c1d0b62b82843a31c43a6 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=4704cb6d92c024c1204c1d0b62b82843a31c43a6 commit 4704cb6d92c024c1204c1d0b62b82843a31c43a6 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-01 09:28:30 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-02 07: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 (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)) {