From nobody Mon Dec 30 19:50:20 2024 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 4YMRXX5LpMz5hgJY; Mon, 30 Dec 2024 19:50:20 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YMRXX37bPz4CdF; Mon, 30 Dec 2024 19:50:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735588220; 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=uPJ3C3Gpo/fvl9fv0nVrkNZC7oXH04qNep/QYNjplxw=; b=H7yjyj+nukOaM3uv52XOp++uTR+pBVeLaB2WB104XT6c3pmlfYc04asIobWU6r4Ikh4UPO xUFSPc55WQUbY9SLnr5VoFCqyZikeGFTdESkkJ0q7TbJQXRIqeSd3O+v/A5F45maEcCCjk qCdWg6UiPKTvRLWL9qvhckHvgZbSmtnyiKlz0DWQc7U5lQzOhLAQjbonvoN7sALcwsB4aK owHS/w2F59RfEoB/P9Tih7F8V32+0O7jsJ3obdvv1jwr9K9DS+V6SMcj9usiEhdVghzXSP fFOa3GQeSzwXjWVVnGKxUto/SP/DczPVa7bT9tXELkWTMiAB3nfU8hTqO/500A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735588220; 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=uPJ3C3Gpo/fvl9fv0nVrkNZC7oXH04qNep/QYNjplxw=; b=yu6tVRhpj/5NxvHbdBj67ERzrzN1tyQmHCWxyVyl4zdZRFg9ppHjFu89b2q4CnoT5togY3 1QLb9uli4tlAe6m0LBpwFLzGx1g4cfv8GaKcPv+wZ1De56EXbOrhPlyDjOnAuGi40Rvqeb 8ZCdeiaPyQsVbhbcGrxbLHUwjXIgGDYnc9nYYJ+Hk+fSIQUI3vCeqDX/Tu1CVA7QNnC84m 0+aAAH0TlZAF5O/pmbbQSNXnbAEY39SfETMGACLU5eRE5/pkvxApQBJ5A2e2P4c3WtUgnz 5XTlkZSUKIqbgLuwRV0qhV5LeyJHFydh9GeQEt/c0a/XT8ebyF8v1KtO8HFa2w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735588220; a=rsa-sha256; cv=none; b=B1xHYBd8Enc+OvXrwhr9IldFyevoR8x/aCMxX9T7v7NnXS0nfNaqPHK6SQe/xhK/G4VYcc pMe6eDhlWFE0wl10Jo9sYnQe0qCFLtKDjgFWtkMFR4BSqUwboJqINN8rRd2DoV5uO52fgl dtWqb5oB9ZSzYc1cTPRotB8NdNsE+Z98BHxnF6YD2UK60Ke9FIuYXqGw3lludKGt6lz3o/ EKfFKs53rgWQI6UNV0Ra1xNhlPJT6t3NaETGpYrpEX74RgPhOVkM/6OU6IJMs8qfAz5w8m /jMOyXz7Tar6mzEU0L0oKJtdRkWV0vGvVEG3YGFrTwVaMoIBc8DnuG4/g80hNQ== 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 4YMRXX2b9Yz172S; Mon, 30 Dec 2024 19:50:20 +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 4BUJoKW2017399; Mon, 30 Dec 2024 19:50:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BUJoKha017396; Mon, 30 Dec 2024 19:50:20 GMT (envelope-from git) Date: Mon, 30 Dec 2024 19:50:20 GMT Message-Id: <202412301950.4BUJoKha017396@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ed Maste Subject: git: 1f31d4374280 - main - makefs: Fix cd9660 duplicate directory names 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1f31d437428014e864bcce1223cf7017180e2608 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=1f31d437428014e864bcce1223cf7017180e2608 commit 1f31d437428014e864bcce1223cf7017180e2608 Author: Ed Maste AuthorDate: 2024-12-30 15:01:06 +0000 Commit: Ed Maste CommitDate: 2024-12-30 19:48:44 +0000 makefs: Fix cd9660 duplicate directory names Previously we could create cd9660 images with duplicate short (level 2) names. cd9660_level2_convert_filename used a 30-character limit (for files and directories), not including the '.' separator. cd9660_rename_filename used a 31-character limit, including the '.'. Directory names 31 characters or longer (without '.') were shortened to 30 characters, and if a collision occurred cd9660_rename_filename uniquified them starting with the 31st character. Unfortunately the directory record's name_len was already set, so the unique part of the name was stripped off. Directories are up to 31 d-characters (i.e., A-Z 0-9 and _); there is no provision for a '.' in a directory name. Increase the name length limit to 31 for directories, and exclude '.'s. This name mapping and deduplication code is still fragile and convoluted and would beenfit from a more holistic effort. PR: 283238, 283112 Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48251 --- usr.sbin/makefs/cd9660.c | 5 ++-- usr.sbin/makefs/tests/makefs_cd9660_tests.sh | 39 ++++++++++++++++++++++++++-- usr.sbin/makefs/tests/makefs_tests_common.sh | 2 +- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c index 63f2e33b978b..687bfe46ac27 100644 --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -1638,14 +1638,15 @@ cd9660_level2_convert_filename(iso9660_disk *diskStructure, const char *oldname, * File version number (5 characters, 1-32767) * 1 <= Sum of File name and File name extension <= 30 */ + int maxlen = is_file ? 30 : 31; int namelen = 0; int extlen = 0; int found_ext = 0; char *orignewname = newname; - while (*oldname != '\0' && namelen + extlen < 30) { + while (*oldname != '\0' && namelen + extlen < maxlen) { /* Handle period first, as it is special */ - if (*oldname == '.') { + if (*oldname == '.' && is_file) { if (found_ext) { if (diskStructure->allow_multidot) { *newname++ = '.'; diff --git a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh index 2fdf47f76a4c..066a9d6ec0e0 100644 --- a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh +++ b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh @@ -51,8 +51,8 @@ common_cleanup() check_base_iso9660_image_contents() { # Symlinks are treated like files when rockridge support isn't - # specified - check_image_contents "$@" -X c + # specified, and directories cannot contain a '.'. + check_image_contents "$@" -X c -X .g -X _g atf_check -e empty -o empty -s exit:0 test -L $TEST_INPUTS_DIR/c atf_check -e empty -o empty -s exit:0 test -f $TEST_MOUNT_DIR/c @@ -374,6 +374,39 @@ o_flag_rockridge_dev_nodes_cleanup() common_cleanup } +atf_test_case duplicate_names cleanup +duplicate_names_head() +{ + atf_set "descr" "Ensure shortened directory names are unique (PR283238)" +} +duplicate_names_body() +{ + check_cd9660_support + create_test_dirs + + # Create three directories which are identical in the first 31 characters. + dir_prefix="this_directory_name_is_31_chars" + mkdir -p $TEST_INPUTS_DIR/${dir_prefix}1 + mkdir -p $TEST_INPUTS_DIR/${dir_prefix}2 + mkdir -p $TEST_INPUTS_DIR/${dir_prefix}3 + + atf_check -e empty -o empty -s exit:0 \ + $MAKEFS -o rockridge $TEST_IMAGE $TEST_INPUTS_DIR + + # Disable Rock Ridge extensions to read the plain ISO Level 2 names. + mount_image -r + + # The specific way the short names are made unique is not important. + # We verify only that there are three unique names and that the unique + # part is at the end of the name. + atf_check_equal $(ls -1 $TEST_MOUNT_DIR | sort | uniq | wc -l) 3 + atf_check_equal $(ls -1 $TEST_MOUNT_DIR | cut -c -29 | sort | uniq | wc -l) 1 +} +duplicate_names_cleanup() +{ + common_cleanup +} + atf_init_test_cases() { atf_add_test_case D_flag @@ -392,4 +425,6 @@ atf_init_test_cases() atf_add_test_case o_flag_publisher atf_add_test_case o_flag_rockridge atf_add_test_case o_flag_rockridge_dev_nodes + + atf_add_test_case duplicate_names } diff --git a/usr.sbin/makefs/tests/makefs_tests_common.sh b/usr.sbin/makefs/tests/makefs_tests_common.sh index 12c7c7c84fb7..b418cafc90a6 100644 --- a/usr.sbin/makefs/tests/makefs_tests_common.sh +++ b/usr.sbin/makefs/tests/makefs_tests_common.sh @@ -138,6 +138,6 @@ mount_image() atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \ mdconfig -a -f $TEST_IMAGE atf_check -e empty -o empty -s exit:0 \ - $MOUNT /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR + $MOUNT ${1} /dev/$(cat $TEST_MD_DEVICE_FILE) $TEST_MOUNT_DIR }