]> The Tcpdump Group git mirrors - tcpdump/commitdiff
ESP: Fix some unreachable code warnings
authorFrancois-Xavier Le Bail <[email protected]>
Sun, 8 Jul 2018 18:01:46 +0000 (20:01 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sun, 8 Jul 2018 18:08:07 +0000 (20:08 +0200)
Found with -Wunreachable-code clang compiler option.

The errors were:
./print-esp.c:263:3: warning: code will never be executed
                                                 [-Wunreachable-code]
                free(input_buffer);
                ^~~~
./print-esp.c:246:3: warning: code will never be executed
                                                 [-Wunreachable-code]
                EVP_CIPHER_CTX_free(ctx);
                ^~~~~~~~~~~~~~~~~~~
./print-esp.c:843:5: warning: code will never be executed
                                                 [-Wunreachable-code]
                                free(input_buffer);
                                ^~~~
./print-esp.c:826:5: warning: code will never be executed
                                                 [-Wunreachable-code]
                                EVP_CIPHER_CTX_free(ctx);
                                ^~~~~~~~~~~~~~~~~~~

print-esp.c

index 5b282526d5572b4d5abb359818b67843a1f407ca..c4d7a75d4e2a02e0eaac92fa1ffccdcd9d1aceae 100644 (file)
@@ -241,10 +241,9 @@ int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
         */
        input_buffer = (u_char *)malloc(buffer_size);
        if (input_buffer == NULL) {
+               EVP_CIPHER_CTX_free(ctx);
                (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
                        "can't allocate memory for encrypted data buffer");
-               EVP_CIPHER_CTX_free(ctx);
-               return 0;
        }
        /*
         * Copy the input data to the encrypted data buffer, and pad it
@@ -258,11 +257,10 @@ int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
         */
        output_buffer = (u_char *)malloc(buffer_size);
        if (output_buffer == NULL) {
-               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
-                       "can't allocate memory for decryption buffer");
                free(input_buffer);
                EVP_CIPHER_CTX_free(ctx);
-               return 0;
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                       "can't allocate memory for decryption buffer");
        }
        EVP_Cipher(ctx, output_buffer, input_buffer, len);
        EVP_CIPHER_CTX_free(ctx);
@@ -821,10 +819,9 @@ esp_print(netdissect_options *ndo,
                         */
                        input_buffer = (u_char *)malloc(buffer_size);
                        if (input_buffer == NULL) {
+                               EVP_CIPHER_CTX_free(ctx);
                                (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
                                        "esp_print: can't allocate memory for encrypted data buffer");
-                               EVP_CIPHER_CTX_free(ctx);
-                               return 0;
                        }
                        /*
                         * Copy the input data to the encrypted data buffer,
@@ -838,11 +835,10 @@ esp_print(netdissect_options *ndo,
                         */
                        output_buffer = (u_char *)malloc(buffer_size);
                        if (output_buffer == NULL) {
-                               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
-                                       "esp_print: can't allocate memory for decryption buffer");
                                free(input_buffer);
                                EVP_CIPHER_CTX_free(ctx);
-                               return -1;
+                               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                                       "esp_print: can't allocate memory for decryption buffer");
                        }
 
                        EVP_Cipher(ctx, output_buffer, input_buffer, len);