diff --git a/libi2pd_client/SAM.cpp b/libi2pd_client/SAM.cpp index 50cb8bf5..7b87b58c 100644 --- a/libi2pd_client/SAM.cpp +++ b/libi2pd_client/SAM.cpp @@ -92,6 +92,7 @@ namespace client { if (ch >= '0' && ch <= '9') { + if (version > MAX_SAM_VERSION_VALUE) continue; // don't overflow on a long number version *= 10; version += (ch - '0'); } diff --git a/libi2pd_client/SAM.h b/libi2pd_client/SAM.h index 0c899661..7959f293 100644 --- a/libi2pd_client/SAM.h +++ b/libi2pd_client/SAM.h @@ -101,6 +101,7 @@ namespace client const char SAM_PONG[] = "PONG %s\n"; constexpr int MAKE_SAM_VERSION_NUMBER (int major, int minor) { return major*10 + minor; } + constexpr int MAX_SAM_VERSION_VALUE = 99999; // stop parsing digits above that, any such version is out of range anyway constexpr int MIN_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 0); constexpr int MAX_SAM_VERSION = MAKE_SAM_VERSION_NUMBER (3, 3); constexpr int SAM_VERSION_33 = MAKE_SAM_VERSION_NUMBER (3, 3); // SAM 3.3