You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/10/28 17:00:07 UTC
[plc4x] branch feature/mspec-ng updated: Adding some sanity checks.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
new f02c403 Adding some sanity checks.
f02c403 is described below
commit f02c4031c853b488409518da3676f3b65af35afc
Author: cdutz <ch...@c-ware.de>
AuthorDate: Thu Oct 28 18:59:51 2021 +0200
Adding some sanity checks.
---
plc4c/CMakeLists.txt | 2 +-
plc4c/transports/tcp/src/transport_tcp.c | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/plc4c/CMakeLists.txt b/plc4c/CMakeLists.txt
index 5cf0693..409b882 100644
--- a/plc4c/CMakeLists.txt
+++ b/plc4c/CMakeLists.txt
@@ -32,7 +32,7 @@ set(PLC4C_ROOT_DIR ${CMAKE_SOURCE_DIR})
set(BUILD_PHASE test-compile CACHE STRING "Phase of the Maven build we are executing cmake")
# Access the Unity version the maven build is providing us with.
-set(UNITY_VERSION 2.5.0 CACHE STRING "Version of the used Unity test framework")
+set(UNITY_VERSION 2.5.2 CACHE STRING "Version of the used Unity test framework")
# MinGW GCC versions above 4.7 on Windows include inline definitions of these functions
# If you run into problems, please read this article: https://stackoverflow.com/questions/27853225/is-there-a-way-to-include-stdio-h-but-ignore-some-of-the-functions-therein
diff --git a/plc4c/transports/tcp/src/transport_tcp.c b/plc4c/transports/tcp/src/transport_tcp.c
index 4861d17..bd7aa3a 100644
--- a/plc4c/transports/tcp/src/transport_tcp.c
+++ b/plc4c/transports/tcp/src/transport_tcp.c
@@ -59,8 +59,6 @@ plc4c_return_code plc4c_transport_tcp_configure_function(
}
plc4c_return_code plc4c_transport_tcp_open_function(void* config) {
- int sockfd;
- int connfd;
struct sockaddr_in servaddr;
plc4c_transport_tcp_config* tcp_config = config;
@@ -131,7 +129,7 @@ plc4c_return_code plc4c_transport_tcp_select_message_function(
if(size_buffer == NULL) {
return NO_MEMORY;
}
- int received_bytes = recv(tcp_config->sockfd, size_buffer, min_size, 0);
+ int received_bytes = recv(tcp_config->sockfd, (char*) size_buffer, min_size, 0);
// TODO: if the value is negative, it's more a "please remove this much of corrupt data" ...
if(received_bytes < 0) {
return CONNECTION_ERROR;
@@ -144,16 +142,20 @@ plc4c_return_code plc4c_transport_tcp_select_message_function(
return INTERNAL_ERROR;
}
uint8_t* message_buffer = malloc(sizeof(uint8_t) * message_size);
- if(message_size < 0) {
+ if(message_buffer < 0) {
return NO_MEMORY;
}
+ // Sanity check
+ if(min_size > message_size) {
+ return INTERNAL_ERROR;
+ }
// Copy the size_buffer to the start of the new buffer.
memcpy(message_buffer, size_buffer, min_size);
free(size_buffer);
// Read the rest of the packet.
- received_bytes = recv(tcp_config->sockfd, message_buffer + min_size, message_size - min_size, 0);
+ received_bytes = recv(tcp_config->sockfd, (char*) message_buffer + min_size, message_size - min_size, 0);
if(received_bytes != message_size - min_size) {
return CONNECTION_ERROR;
}