The branch stable/14 has been updated by emaste:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=fb0239e69f17400b08421a002a72b9520afd8285

commit fb0239e69f17400b08421a002a72b9520afd8285
Author:     Ed Maste <ema...@freebsd.org>
AuthorDate: 2024-12-22 16:00:49 +0000
Commit:     Ed Maste <ema...@freebsd.org>
CommitDate: 2025-01-14 21:07:39 +0000

    makefs: Crudely fix a sprintf warning
    
    Reviewed by:    kevans
    Obtained from:  OpenBSD d95291fdb2dc
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D48178
    
    (cherry picked from commit 2069f6ecb1b1268deac980176c652ffab264970e)
---
 usr.sbin/makefs/cd9660.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/usr.sbin/makefs/cd9660.c b/usr.sbin/makefs/cd9660.c
index bb3a86b7c8b5..0263970bba89 100644
--- a/usr.sbin/makefs/cd9660.c
+++ b/usr.sbin/makefs/cd9660.c
@@ -142,10 +142,11 @@ static void cd9660_convert_structure(iso9660_disk *, 
fsnode *, cd9660node *, int
 static void cd9660_free_structure(cd9660node *);
 static int cd9660_generate_path_table(iso9660_disk *);
 static int cd9660_level1_convert_filename(iso9660_disk *, const char *, char *,
-    int);
+    size_t, int);
 static int cd9660_level2_convert_filename(iso9660_disk *, const char *, char *,
+    size_t, int);
+static int cd9660_convert_filename(iso9660_disk *, const char *, char *, 
size_t,
     int);
-static int cd9660_convert_filename(iso9660_disk *, const char *, char *, int);
 static void cd9660_populate_dot_records(iso9660_disk *, cd9660node *);
 static int64_t cd9660_compute_offsets(iso9660_disk *, cd9660node *, int64_t);
 #if 0
@@ -225,7 +226,8 @@ cd9660_set_defaults(iso9660_disk *diskStructure)
        memset(diskStructure->primaryDescriptor.abstract_file_id, 0x20,37);
        memset(diskStructure->primaryDescriptor.bibliographic_file_id, 0x20,37);
 
-       strcpy(diskStructure->primaryDescriptor.system_id, "FreeBSD");
+       strlcpy(diskStructure->primaryDescriptor.system_id, "FreeBSD",
+           sizeof(diskStructure->primaryDescriptor.system_id));
 
        /* Boot support: Initially disabled */
        diskStructure->has_generic_bootimage = 0;
@@ -809,7 +811,7 @@ cd9660_translate_node_common(iso9660_disk *diskStructure, 
cd9660node *newnode)
        memset(temp, 0, ISO_FILENAME_MAXLENGTH_WITH_PADDING);
 
        (void)cd9660_convert_filename(diskStructure, newnode->node->name,
-           temp, !(S_ISDIR(newnode->node->type)));
+           temp, sizeof(temp), !(S_ISDIR(newnode->node->type)));
 
        flag = ISO_FLAG_CLEAR;
        if (S_ISDIR(newnode->node->type))
@@ -1112,7 +1114,9 @@ cd9660_rename_filename(iso9660_disk *diskStructure, 
cd9660node *iter, int num,
                while (digits > 0) {
                        digit = (int)(temp / powers);
                        temp = temp - digit * powers;
-                       sprintf(&tmp[numbts] , "%d", digit);
+                       snprintf(&tmp[numbts],
+                           ISO_FILENAME_MAXLENGTH_WITH_PADDING - numbts,
+                           "%d", digit);
                        digits--;
                        numbts++;
                        powers = powers / 10;
@@ -1578,7 +1582,7 @@ cd9660_compute_full_filename(cd9660node *node, char *buf)
  */
 static int
 cd9660_level1_convert_filename(iso9660_disk *diskStructure, const char 
*oldname,
-    char *newname, int is_file)
+    char *newname, size_t newnamelen, int is_file)
 {
        /*
         * ISO 9660 : 10.1
@@ -1589,6 +1593,7 @@ cd9660_level1_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
        int namelen = 0;
        int extlen = 0;
        int found_ext = 0;
+       char *orignewname = newname;
 
        while (*oldname != '\0' && extlen < 3) {
                /* Handle period first, as it is special */
@@ -1630,7 +1635,7 @@ cd9660_level1_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
                if (!found_ext && !diskStructure->omit_trailing_period)
                        *newname++ = '.';
                /* Add version */
-               sprintf(newname, ";%i", 1);
+               snprintf(newname, newnamelen - (newname - orignewname), ";%i", 
1);
        }
        return namelen + extlen + found_ext;
 }
@@ -1638,7 +1643,7 @@ cd9660_level1_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
 /* XXX bounds checking! */
 static int
 cd9660_level2_convert_filename(iso9660_disk *diskStructure, const char 
*oldname,
-    char *newname, int is_file)
+    char *newname, size_t newnamelen, int is_file)
 {
        /*
         * ISO 9660 : 7.5.1
@@ -1652,6 +1657,7 @@ cd9660_level2_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
        int namelen = 0;
        int extlen = 0;
        int found_ext = 0;
+       char *orignewname = newname;
 
        while (*oldname != '\0' && namelen + extlen < 30) {
                /* Handle period first, as it is special */
@@ -1697,7 +1703,7 @@ cd9660_level2_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
                if (!found_ext && !diskStructure->omit_trailing_period)
                        *newname++ = '.';
                /* Add version */
-               sprintf(newname, ";%i", 1);
+               snprintf(newname, newnamelen - (newname - orignewname), ";%i", 
1);
        }
        return namelen + extlen + found_ext;
 }
@@ -1712,15 +1718,15 @@ cd9660_level2_convert_filename(iso9660_disk 
*diskStructure, const char *oldname,
  */
 static int
 cd9660_convert_filename(iso9660_disk *diskStructure, const char *oldname,
-    char *newname, int is_file)
+    char *newname, size_t newnamelen, int is_file)
 {
        assert(1 <= diskStructure->isoLevel && diskStructure->isoLevel <= 2);
        if (diskStructure->isoLevel == 1)
                return(cd9660_level1_convert_filename(diskStructure,
-                   oldname, newname, is_file));
+                   oldname, newname, newnamelen, is_file));
        else if (diskStructure->isoLevel == 2)
                return (cd9660_level2_convert_filename(diskStructure,
-                   oldname, newname, is_file));
+                   oldname, newname, newnamelen, is_file));
        abort();
 }
 
@@ -1932,7 +1938,7 @@ cd9660_create_virtual_entry(iso9660_disk *diskStructure, 
const char *name,
        temp->isoDirRecord = emalloc(sizeof(*temp->isoDirRecord));
 
        cd9660_convert_filename(diskStructure, tfsnode->name,
-           temp->isoDirRecord->name, file);
+           temp->isoDirRecord->name, sizeof(temp->isoDirRecord->name), file);
 
        temp->node = tfsnode;
        temp->parent = parent;

Reply via email to