diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -1638,14 +1638,15 @@ * 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 --- a/usr.sbin/makefs/tests/makefs_cd9660_tests.sh +++ b/usr.sbin/makefs/tests/makefs_cd9660_tests.sh @@ -51,8 +51,8 @@ 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 @@ 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_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 --- a/usr.sbin/makefs/tests/makefs_tests_common.sh +++ b/usr.sbin/makefs/tests/makefs_tests_common.sh @@ -138,6 +138,6 @@ 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 }