From 9ebc510d97293c40bb38fb5c3d4a7cb69252b57e Mon Sep 17 00:00:00 2001 From: longshijing <1417449807@qq.com> Date: Thu, 10 Nov 2022 21:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E7=BB=84=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/callback_func.c | 8 ++++++++ src/util/string_util.c | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/service/callback_func.c b/src/service/callback_func.c index fee5725..86f0d6e 100644 --- a/src/service/callback_func.c +++ b/src/service/callback_func.c @@ -622,6 +622,10 @@ void OnMessageArrived(void *context, int token, int code, const char *topic, cha event->services[i].paras->devices_count = devices_count; long long version = getLLongValueFromStr(message, VERSION_JSON); + if (version < 0){ + PrintfLog(EN_LOG_LEVEL_ERROR, "getLLongValueFromStr(), Length out of bounds. Modifiable value LONG_LONG_MAX_LENGTH\n"); + break; + } event->services[i].paras->version = version; int j = 0; @@ -899,6 +903,10 @@ void OnMessageArrived(void *context, int token, int code, const char *topic, cha long long device_send_time = getLLongValueFromStr(message, DEVICE_SEND_TIME_JSON); long long server_recv_time = getLLongValueFromStr(message, SERVER_RECV_TIME_JSON); long long server_send_time = getLLongValueFromStr(message, SERVER_SEND_TIME_JSON); + if (device_send_time < 0 || server_recv_time < 0 || server_send_time < 0){ + PrintfLog(EN_LOG_LEVEL_ERROR, "getLLongValueFromStr(), Length out of bounds. Modifiable value LONG_LONG_MAX_LENGTH\n"); + break; + } event->services[i].ntp_paras->device_real_time = (server_recv_time + server_send_time + getTime() - device_send_time) / 2; } diff --git a/src/util/string_util.c b/src/util/string_util.c index 151fdcd..337f6f7 100644 --- a/src/util/string_util.c +++ b/src/util/string_util.c @@ -224,6 +224,9 @@ long long getLLongValueFromStr (const* str, const *subStr) { if (version_tmp[i] >= '0' && version_tmp[i] <= '9') { buf[j] = version_tmp[i]; j++; + if (j > LONG_LONG_MAX_LENGTH) { + return -1; + } } else { if (j > 0) { break; @@ -231,8 +234,6 @@ long long getLLongValueFromStr (const* str, const *subStr) { } } - buf[i] = '\0'; - char *end = NULL; long long version = strtoll(buf, &end, 10); return version;