]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
enip: fix compile warnings in gcc-8 4252/head
authorVictor Julien <victor@inliniac.net>
Sat, 28 Sep 2019 08:55:34 +0000 (10:55 +0200)
committerVictor Julien <victor@inliniac.net>
Sun, 29 Sep 2019 05:49:36 +0000 (07:49 +0200)
In file included from suricata-common.h:471,
                 from app-layer-enip-common.c:27:
app-layer-enip-common.c: In function ‘DecodeCIPRequestPathPDU’:
util-debug.h:222:31: warning: ‘req_path_class8’ may be used uninitialized in this function [-Wmaybe-uninitialized]
             int _sc_log_ret = snprintf(_sc_log_msg, SC_LOG_MAX_LOG_MSG_LEN, __VA_ARGS__);   \
                               ^~~~~~~~
app-layer-enip-common.c:589:13: note: ‘req_path_class8’ was declared here
     uint8_t req_path_class8;
             ^~~~~~~~~~~~~~~
app-layer-enip-common.c:607:9: warning: ‘segment’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         switch (segment)
         ^~~~~~
app-layer-enip-common.c: In function ‘DecodeCIPResponsePDU’:
app-layer-enip-common.c:773:13: warning: ‘service’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     service &= 0x7f; //strip off top bit to get service code.  Responses have first bit as 1
             ^~
app-layer-enip-common.c: In function ‘DecodeCIPRequestPDU’:
app-layer-enip-common.c:503:25: warning: ‘path_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     offset += path_size * sizeof(uint16_t); //move offset past pathsize
               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~
app-layer-enip-common.c:506:5: warning: ‘service’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     switch (service)
     ^~~~~~

Bug #3139.

src/app-layer-enip-common.c

index d31e24364746039663f27f3d2c826f0ef4fc3792..91f06e731f88865d5db00bd6ec8754af5474ffb1 100644 (file)
@@ -459,8 +459,8 @@ int DecodeCIPRequestPDU(const uint8_t *input, uint32_t input_len,
         return 0;
     }
 
-    uint8_t service; //<-----CIP SERVICE
-    uint8_t path_size;
+    uint8_t service = 0; //<-----CIP SERVICE
+    uint8_t path_size = 0;
 
     if (ENIPExtractUint8(&service, input, &offset, input_len) != 1)
     {
@@ -489,7 +489,7 @@ int DecodeCIPRequestPDU(const uint8_t *input, uint32_t input_len,
     if (node == NULL)
     {
         SCLogDebug("DecodeCIPRequest: Unable to create CIP service");
-       return 0;
+        return 0;
     }
     node->direction = 0;
     node->service = service;
@@ -582,11 +582,9 @@ int DecodeCIPRequestPathPDU(const uint8_t *input, uint32_t input_len,
 
     int bytes_remain = node->request.path_size;
 
-    uint8_t segment;
     uint8_t reserved; //unused byte reserved by ODVA
 
     //8 bit fields
-    uint8_t req_path_class8;
     uint8_t req_path_instance8;
     uint8_t req_path_attr8;
 
@@ -600,15 +598,16 @@ int DecodeCIPRequestPathPDU(const uint8_t *input, uint32_t input_len,
 
     while (bytes_remain > 0)
     {
+        uint8_t segment = 0;
         if (ENIPExtractUint8(&segment, input, &offset, input_len) != 1)
         {
             return 0;
         }
         switch (segment)
         { //assume order is class then instance.  Can have multiple
-            case PATH_CLASS_8BIT:
-                if (ENIPExtractUint8(&req_path_class8, input, &offset, input_len) != 1)
-                {
+            case PATH_CLASS_8BIT: {
+                uint8_t req_path_class8 = 0;
+                if (ENIPExtractUint8(&req_path_class8, input, &offset, input_len) != 1) {
                     return 0;
                 }
                 class = (uint16_t) req_path_class8;
@@ -623,6 +622,7 @@ int DecodeCIPRequestPathPDU(const uint8_t *input, uint32_t input_len,
 
                 bytes_remain--;
                 break;
+            }
             case PATH_INSTANCE_8BIT:
                 if (ENIPExtractUint8(&req_path_instance8, input, &offset, input_len) != 1)
                 {
@@ -752,7 +752,7 @@ int DecodeCIPResponsePDU(const uint8_t *input, uint32_t input_len,
         return 0;
     }
 
-    uint8_t service; //<----CIP SERVICE
+    uint8_t service = 0; //<----CIP SERVICE
     uint8_t reserved; //unused byte reserved by ODVA
     uint16_t status;