aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Deri <lucaderi@users.noreply.github.com>2020-06-05 16:57:46 +0200
committerGitHub <noreply@github.com>2020-06-05 16:57:46 +0200
commit597d6e5d60f9d51c45338d60d232599a3c00d390 (patch)
treea0daa5d312e947ef6f6bbedea247cbd5b5cff9d2
parent67c72a8cb59f09c5740d8c16f6db7bdddb2dece0 (diff)
parent40550073ef0ed6261cd7f95ffb07312f32e562c1 (diff)
Merge pull request #913 from yskcg/fix_segment_fault_dev
Fix segment fault dev
-rw-r--r--example/reader_util.c2
-rw-r--r--src/lib/ndpi_main.c4
-rw-r--r--src/lib/protocols/someip.c14
3 files changed, 16 insertions, 4 deletions
diff --git a/example/reader_util.c b/example/reader_util.c
index 2c719286f..833f200bf 100644
--- a/example/reader_util.c
+++ b/example/reader_util.c
@@ -1099,7 +1099,7 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
sizeof(flow->ssh_tls.client_requested_server_name), "%s",
flow->ndpi_flow->protos.stun_ssl.ssl.client_requested_server_name);
- if(flow->ndpi_flow->protos.stun_ssl.ssl.server_names_len > 0)
+ if(flow->ndpi_flow->protos.stun_ssl.ssl.server_names_len > 0 && flow->ndpi_flow->protos.stun_ssl.ssl.server_names)
flow->ssh_tls.server_names = ndpi_strdup(flow->ndpi_flow->protos.stun_ssl.ssl.server_names);
flow->ssh_tls.notBefore = flow->ndpi_flow->protos.stun_ssl.ssl.notBefore;
flow->ssh_tls.notAfter = flow->ndpi_flow->protos.stun_ssl.ssl.notAfter;
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 3cc554481..fed3c9831 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -131,6 +131,10 @@ void *ndpi_realloc(void *ptr, size_t old_size, size_t new_size) {
/* ****************************************** */
char *ndpi_strdup(const char *s) {
+ if( s == NULL ){
+ return NULL;
+ }
+
int len = strlen(s);
char *m = ndpi_malloc(len + 1);
diff --git a/src/lib/protocols/someip.c b/src/lib/protocols/someip.c
index 9211a4b85..e894d6390 100644
--- a/src/lib/protocols/someip.c
+++ b/src/lib/protocols/someip.c
@@ -87,6 +87,14 @@ static void ndpi_int_someip_add_connection (struct ndpi_detection_module_struct
NDPI_LOG_INFO(ndpi_struct, "found SOME/IP\n");
}
+static u_int32_t someip_data_cover_32(const u_int8_t *data)
+{
+ u_int32_t value;
+
+ memcpy(&value,data,sizeof(u_int32_t));
+
+ return value;
+}
/**
* Dissector function that searches SOME/IP headers
*/
@@ -111,8 +119,8 @@ void ndpi_search_someip (struct ndpi_detection_module_struct *ndpi_struct,
}
//we extract the Message ID and Request ID and check for special cases later
- u_int32_t message_id = ntohl(*((u_int32_t *)&packet->payload[0]));
- u_int32_t request_id = ntohl(*((u_int32_t *)&packet->payload[8]));
+ u_int32_t message_id = ntohl(someip_data_cover_32(&packet->payload[0]));
+ u_int32_t request_id = ntohl(someip_data_cover_32(&packet->payload[8]));
NDPI_LOG_DBG2(ndpi_struct, "====>>>> SOME/IP Message ID: %08x [len: %u]\n",
message_id, packet->payload_packet_len);
@@ -125,7 +133,7 @@ void ndpi_search_someip (struct ndpi_detection_module_struct *ndpi_struct,
//####Maximum packet size in SOMEIP depends on the carrier protocol, and I'm not certain how well enforced it is, so let's leave that for round 2####
// we extract the remaining length
- u_int32_t someip_len = ntohl(*((u_int32_t *)&packet->payload[4]));
+ u_int32_t someip_len = ntohl(someip_data_cover_32(&packet->payload[4]));
if (packet->payload_packet_len != (someip_len + 8)) {
NDPI_LOG_DBG(ndpi_struct, "Excluding SOME/IP .. Length field invalid!\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SOMEIP);