From 793431aed3f84cce9cb4bea0c91a5e9f55a7c21e Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 3 Oct 2026 11:04:54 -0400 Subject: [PATCH] use std::stoi for conversion from hex string --- libi2pd/HTTP.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index 7791cd76..1b68cc17 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -607,12 +607,16 @@ namespace http while (!in.eof ()) { std::getline (in, hexLen); - errno = 0; - long int len = strtoul(hexLen.c_str(), (char **) NULL, 16); - if (errno != 0) - return false; /* conversion error */ - if (len == 0) - return true; /* end of stream */ + long len = 0; + try + { + len = std::stoi (hexLen, nullptr, 16); + } + catch (std::exception& ex) + { + return false; + } + if (!len) return true; // end of stream if (len < 0 || len > 10 * 1024 * 1024) /* < 10Mb */ return false; /* too large chunk */ char * buf = new char[len];