Skip to content

Commit

Permalink
Merge pull request #41 from longshijing/master
Browse files Browse the repository at this point in the history
修复数组越界问题
  • Loading branch information
louiscrazy authored Nov 11, 2022
2 parents d38a112 + 9ebc510 commit e405a2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/service/callback_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/util/string_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,16 @@ 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;
}
}
}

buf[i] = '\0';

char *end = NULL;
long long version = strtoll(buf, &end, 10);
return version;
Expand Down

0 comments on commit e405a2e

Please sign in to comment.