From f4f302982e03de805b59f1841ea4ed8cb8cda8ea Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 4 Dec 2023 10:57:52 -1000 Subject: [PATCH] TAPE: Fix potential buffer overflow when staging an in memory ANSI tape image --- sim_tape.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sim_tape.c b/sim_tape.c index 66df0b17..458cd42b 100644 --- a/sim_tape.c +++ b/sim_tape.c @@ -4543,9 +4543,9 @@ static void ansi_make_HDR1 (HDR1 *hdr1, VOL1 *vol, HDR4 *hdr4, const char *filen memcpy (hdr4->type, "HDR", 3); hdr4->num = '4'; to_ansi_a (hdr1->file_ident, fn, sizeof (hdr1->file_ident)); - if (strlen (fn) > 17) { - to_ansi_a (hdr4->extra_name, fn + 17, sizeof (hdr4->extra_name)); - sprintf (extra_name_used, "%02d", (int)(strlen (fn) - 17)); + if (strlen (fn) > sizeof (hdr1->file_ident)) { + to_ansi_a (hdr4->extra_name, fn + sizeof (hdr1->file_ident), sizeof (hdr4->extra_name)); + snprintf (extra_name_used, sizeof (extra_name_used), "%02d", (int)(MIN((strlen (fn) - sizeof (hdr1->file_ident)), sizeof (hdr4->extra_name)))); } memcpy (hdr4->extra_name_used, extra_name_used, 2); memcpy (hdr1->file_set, vol->ident, sizeof (hdr1->file_set));