# HG changeset patch # User Alain Mazy # Date 1778521312 -7200 # Node ID eabb2b48543746780c366f444ec0ae753275fc97 # Parent 271c0a3ae375d81c66f14ef652e47ce4b9c0b446# Parent 76bf4629d7974b1f5f3d022d1f16a78929f57df0 merge diff -r 76bf4629d797 -r eabb2b485437 OrthancFramework/Sources/SystemToolbox.cpp --- a/OrthancFramework/Sources/SystemToolbox.cpp Mon May 11 18:48:47 2026 +0200 +++ b/OrthancFramework/Sources/SystemToolbox.cpp Mon May 11 19:41:52 2026 +0200 @@ -289,15 +289,15 @@ bool full = true; { - std::streamsize size = GetStreamSize(f); - if (size <= 0) + std::streamsize fileSize = GetStreamSize(f); + if (fileSize <= 0) { headerSize = 0; full = false; } - else if (static_cast(size) < headerSize) + else if (static_cast(fileSize) < headerSize) { - headerSize = static_cast(size); // Truncate to the size of the file + headerSize = static_cast(fileSize); // Truncate to the size of the file full = false; } } @@ -305,7 +305,7 @@ header.resize(headerSize); if (headerSize != 0) { - f.read(&header[0], headerSize); + f.read(&header[0], static_cast(headerSize)); } f.close(); @@ -340,7 +340,12 @@ if (size != 0) { - f.write(reinterpret_cast(content), size); + if (size > static_cast(std::numeric_limits::max())) + { + throw OrthancException(ErrorCode_CannotWriteFile, "Size too large to fit in a streamsize"); + } + + f.write(reinterpret_cast(content), static_cast(size)); if (!f.good()) { @@ -737,7 +742,7 @@ status.type() == boost::filesystem::reparse_file); // Fix BitBucket issue #11 } } - catch (boost::filesystem::filesystem_error&) + catch (boost::filesystem::filesystem_error&) // NOLINT(bugprone-empty-catch) { } @@ -1101,7 +1106,7 @@ if (!content.empty()) { - f.seekg(start, std::ios::beg); + f.seekg(static_cast(start), std::ios::beg); f.read(&content[0], static_cast(content.size())); } } @@ -1297,7 +1302,12 @@ #else struct ifreq ifr; - strcpy(ifr.ifr_name, interfaces.GetCurrentName()); + if (strlen(interfaces.GetCurrentName()) > (IF_NAMESIZE - 1)) + { + throw OrthancException(ErrorCode_InternalError, std::string("Network interface name too long: '") + interfaces.GetCurrentName() + "'"); + } + + strcpy(ifr.ifr_name, interfaces.GetCurrentName()); // NOLINT(clang-analyzer-security.insecureAPI.strcpy) if (ioctl(socket.GetDescriptor(), SIOCGIFFLAGS, &ifr) == 0 && !(ifr.ifr_flags & IFF_LOOPBACK) && // ignore loopback interface