From nobody Thu Dec 26 16:45:44 2024 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 4YJvdN4RlRz5jKY6; Thu, 26 Dec 2024 16:45:44 +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 4YJvdN2W2bz4kk9; Thu, 26 Dec 2024 16:45:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735231544; 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=wcwRne9cn+Ps8njhTPvHRmlNeWeRmGIBPkuBOZ9tOfE=; b=q5owFZTLad4ZASWKMPDFrU9DGvFAk3OwZNtu+ErlKCozfJ1XRA9dYIdXywPXZQlmoDeVcY O3kBi7FI+FbOXOpQpaqAtbIXWaUE4uynau+LbXSbAgaIbUGzFvtWF35wYj/CHDiSV4ubE5 xijgNmJeZKuM+h1K3i7Z/3Y29Um2F/oJ4E7MjG04wtxl0e73sep1d9B7VYBllWYlwvss9j sQjC4B3yVf5vtkeySJdnM37At4n8q489UwPTBs6Kz41rkvJMi55neHPPt0N4hpmFhcwbVT P4qE2g6ghpfpQYP8Es85dHm0fJq1kRU3KNq8chAEljQ99fRmoTT7HkiLGojO7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735231544; 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=wcwRne9cn+Ps8njhTPvHRmlNeWeRmGIBPkuBOZ9tOfE=; b=Mhbk23lymmof/kzY1Xy5sZbZcowDaqMAsM/P4vcE/JhYb9znTHdVn6STIwae0IJnL1b87s v5JLqdObjMOOTlp2nLlg/yb+XRThggkiQfyynvvLxxmlcAVeX95coyl47kUtTcLR9NQEc8 28xOlGoCkmqGC1Oyv7YH2WrGgQp/dv721RDZ7rOLM/pxo+PJgjTYK52B8tUshJOcuzun1j 0XUJ3seYnbT0nAt02PF2JAWJUmSZYovFurE+YkSwWRbkUFXWLwA1sqXs/t6xBDVcZdRbFD WCxcsHQMUAwOW0RrP6ULVZgspoPdF8IFYOUlXNUSma1G9sAhRxBvwUFZs0BpGg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735231544; a=rsa-sha256; cv=none; b=xHFV2/0k4K473RNL/T+5W4zrE0mrPpHm2ByE3XtHg3BpKSmUhyJUxPHYUYQae/YHhrAJcZ 3C3Uc+W5qol0eWa4Rfj7Qp5xWd0E0shlsxJa09Hf4Z51zFqIV5SQiBS14GFzyfmKCDXWvJ imkm/6wB28Dg+KNCOWgFaq9vxlOXxlDOjgzl9hh+zzDNgkTtWvsJS/UAQp+YEOjjFWHkLR R1aLmiiUlRJZKcqfeRRtI9lgeFmsGpi5Du5mPS1370h7CI/8B/MTDV/b1IvXz8tBJFJ0bx BFHDJ8hJ726TrXoVrRDntBkMnzzFDYCjNL/bnElgUtUUv7puZ25skNhdsQkDYA== 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 4YJvdN1kMmz12dK; Thu, 26 Dec 2024 16:45:44 +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 4BQGjiV1009454; Thu, 26 Dec 2024 16:45:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BQGjiju009451; Thu, 26 Dec 2024 16:45:44 GMT (envelope-from git) Date: Thu, 26 Dec 2024 16:45:44 GMT Message-Id: <202412261645.4BQGjiju009451@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: 2e09cef8dc6f - main - makefs: Fix cd9660 filename buffer maximum length 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2e09cef8dc6f46faba8bab87c42c3f19ba2ffe87 Auto-Submitted: auto-generated The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=2e09cef8dc6f46faba8bab87c42c3f19ba2ffe87 commit 2e09cef8dc6f46faba8bab87c42c3f19ba2ffe87 Author: Ed Maste AuthorDate: 2024-12-24 16:08:10 +0000 Commit: Ed Maste CommitDate: 2024-12-26 16:44:36 +0000 makefs: Fix cd9660 filename buffer maximum length The maximum length is 30 characters for name and extension, two separators (. and ;) and 5 characters for file version from 1 to 32767, which is 37 characters. Add one for the null term as we treat these buffers as C strings. This is not an issue in practice, as the file version is always 1 in makefs. While here, drop `_WITH_PADDING` from the macro name and update the previously-unused ISO_FILENAME_MAXLENGTH for the corrected length. A 0x00 padding byte is used by ISO9660 when needed for alignment, which can be the null byte at the end of the string. Use sizeof where appropriate. Reviewed by: kevans Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48193 --- usr.sbin/makefs/cd9660.c | 16 +++++++--------- usr.sbin/makefs/cd9660.h | 9 ++++----- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c index d3baa3b78a6e..bc9895730b84 100644 --- a/usr.sbin/makefs/cd9660.c +++ b/usr.sbin/makefs/cd9660.c @@ -497,7 +497,7 @@ cd9660_makefs(const char *image, const char *dir, fsnode *root, real_root->isoDirRecord = emalloc(sizeof(*real_root->isoDirRecord)); /* Leave filename blank for root */ memset(real_root->isoDirRecord->name, 0, - ISO_FILENAME_MAXLENGTH_WITH_PADDING); + sizeof(real_root->isoDirRecord->name)); real_root->level = 0; diskStructure->rootNode = real_root; @@ -796,10 +796,10 @@ static int cd9660_translate_node_common(iso9660_disk *diskStructure, cd9660node *newnode) { u_char flag; - char temp[ISO_FILENAME_MAXLENGTH_WITH_PADDING]; + char temp[ISO_FILENAME_MAXLENGTH]; /* Now populate the isoDirRecord structure */ - memset(temp, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING); + memset(temp, 0, sizeof(temp)); (void)cd9660_convert_filename(diskStructure, newnode->node->name, temp, sizeof(temp), !(S_ISDIR(newnode->node->type))); @@ -1044,7 +1044,7 @@ cd9660_rename_filename(iso9660_disk *diskStructure, cd9660node *iter, int num, else maxlength = ISO_FILENAME_MAXLENGTH_BEFORE_VERSION; - tmp = emalloc(ISO_FILENAME_MAXLENGTH_WITH_PADDING); + tmp = emalloc(ISO_FILENAME_MAXLENGTH); while (i < num && iter) { powers = 1; @@ -1105,8 +1105,7 @@ cd9660_rename_filename(iso9660_disk *diskStructure, cd9660node *iter, int num, while (digits > 0) { digit = (int)(temp / powers); temp = temp - digit * powers; - snprintf(&tmp[numbts], - ISO_FILENAME_MAXLENGTH_WITH_PADDING - numbts, + snprintf(&tmp[numbts], ISO_FILENAME_MAXLENGTH - numbts, "%d", digit); digits--; numbts++; @@ -1153,8 +1152,7 @@ cd9660_copy_filenames(iso9660_disk *diskStructure, cd9660node *node) TAILQ_FOREACH(cn, &node->cn_children, cn_next_child) { cd9660_copy_filenames(diskStructure, cn); - memcpy(cn->o_name, cn->isoDirRecord->name, - ISO_FILENAME_MAXLENGTH_WITH_PADDING); + memcpy(cn->o_name, cn->isoDirRecord->name, sizeof(cn->o_name)); } } @@ -1277,7 +1275,7 @@ cd9660_rrip_move_directory(iso9660_disk *diskStructure, cd9660node *dir) /* TODO: Inherit permissions / ownership (basically the entire inode) */ /* Set the new name */ - memset(dir->isoDirRecord->name, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING); + memset(dir->isoDirRecord->name, 0, sizeof(dir->isoDirRecord->name)); strncpy(dir->isoDirRecord->name, newname, 8); dir->isoDirRecord->length[0] = 34 + 8; dir->isoDirRecord->name_len[0] = 8; diff --git a/usr.sbin/makefs/cd9660.h b/usr.sbin/makefs/cd9660.h index bc826a414a6d..b2db31460d02 100644 --- a/usr.sbin/makefs/cd9660.h +++ b/usr.sbin/makefs/cd9660.h @@ -72,8 +72,7 @@ /*30 for name and extension, as well as version number and padding bit*/ #define ISO_FILENAME_MAXLENGTH_BEFORE_VERSION 30 -#define ISO_FILENAME_MAXLENGTH 36 -#define ISO_FILENAME_MAXLENGTH_WITH_PADDING 37 +#define ISO_FILENAME_MAXLENGTH 38 #define ISO_FLAG_CLEAR 0x00 #define ISO_FLAG_HIDDEN 0x01 @@ -118,7 +117,7 @@ typedef struct _iso_directory_record_cd9660 { u_char interleave [ISODCL (28, 28)]; /* 711 */ u_char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ u_char name_len [ISODCL (33, 33)]; /* 711 */ - char name [ISO_FILENAME_MAXLENGTH_WITH_PADDING]; + char name [ISO_FILENAME_MAXLENGTH]; } iso_directory_record_cd9660; /* TODO: Lots of optimization of this structure */ @@ -154,7 +153,7 @@ typedef struct _cd9660node { int fileRecordSize;/*copy of a variable, int for quicker calculations*/ /* Old name, used for renaming - needs to be optimized but low priority */ - char o_name [ISO_FILENAME_MAXLENGTH_WITH_PADDING]; + char o_name [ISO_FILENAME_MAXLENGTH]; /***** SPACE RESERVED FOR EXTENSIONS *****/ /* For memory efficiency's sake - we should move this to a separate struct @@ -194,7 +193,7 @@ typedef struct _path_table_entry u_char extended_attribute_length[ISODCL (2, 2)]; u_char first_sector[ISODCL (3, 6)]; u_char parent_number[ISODCL (7, 8)]; - char name[ISO_FILENAME_MAXLENGTH_WITH_PADDING]; + char name[ISO_FILENAME_MAXLENGTH]; } path_table_entry; typedef struct _volume_descriptor