From b960a5c87f767b81052997abe5e7db41be606133 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 15 Oct 2023 14:04:19 +0100 Subject: [PATCH] apple2: network open: stop at nul if present --- lib/device/iwm/network.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/device/iwm/network.cpp b/lib/device/iwm/network.cpp index 2d83833ec..fbb79c314 100755 --- a/lib/device/iwm/network.cpp +++ b/lib/device/iwm/network.cpp @@ -125,10 +125,15 @@ void iwmNetwork::send_status_dib_reply_packet() */ void iwmNetwork::open() { - int idx = 0; - uint8_t _aux1 = data_buffer[idx++]; - uint8_t _aux2 = data_buffer[idx++]; - string d = string((char *)&data_buffer[idx], 256); + uint8_t _aux1 = data_buffer[0]; + uint8_t _aux2 = data_buffer[1]; + + auto start = data_buffer + 2; + auto end = start + std::min(256, sizeof(data_buffer) - 2); + auto null_pos = std::find(start, end, 0); + + // ensure the string does not go past a null, but can be up to 256 bytes long if one not found + string d(start, null_pos); Debug_printf("\naux1: %u aux2: %u path %s", _aux1, _aux2, d.c_str());