| File: | builds/wireshark/wireshark/epan/tvbuff_snappy.c |
| Warning: | line 48, column 25 Potential leak of memory pointed to by 'decompressed_buffer' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* tvbuff_snappy.c | |||
| 2 | * | |||
| 3 | * Wireshark - Network traffic analyzer | |||
| 4 | * By Gerald Combs <gerald@wireshark.org> | |||
| 5 | * Copyright 1998 Gerald Combs | |||
| 6 | * | |||
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later | |||
| 8 | */ | |||
| 9 | ||||
| 10 | #include <config.h> | |||
| 11 | ||||
| 12 | #ifdef HAVE_SNAPPY1 | |||
| 13 | #include <snappy-c.h> | |||
| 14 | #endif | |||
| 15 | ||||
| 16 | #include "tvbuff.h" | |||
| 17 | ||||
| 18 | #ifdef HAVE_SNAPPY1 | |||
| 19 | ||||
| 20 | /* | |||
| 21 | * Uncompresses a snappy compressed packet inside a message of tvb at offset with | |||
| 22 | * length comprlen. Returns an uncompressed tvbuffer if uncompression | |||
| 23 | * succeeded or NULL if uncompression failed. | |||
| 24 | */ | |||
| 25 | ||||
| 26 | tvbuff_t * | |||
| 27 | tvb_uncompress_snappy(tvbuff_t *tvb, const unsigned offset, unsigned comprlen) | |||
| 28 | { | |||
| 29 | tvbuff_t *uncompr_tvb = NULL((void*)0); | |||
| 30 | unsigned char *decompressed_buffer = NULL((void*)0); | |||
| 31 | size_t orig_size = 0; | |||
| 32 | snappy_status ret; | |||
| 33 | const void *compr_ptr; | |||
| 34 | ||||
| 35 | if (tvb == NULL((void*)0) || comprlen <= 0 || comprlen > tvb_captured_length_remaining(tvb, offset)) { | |||
| 36 | return NULL((void*)0); | |||
| 37 | } | |||
| 38 | ||||
| 39 | compr_ptr = tvb_get_ptr(tvb, offset, comprlen); | |||
| 40 | ret = snappy_uncompressed_length(compr_ptr, comprlen, &orig_size); | |||
| 41 | ||||
| 42 | if (ret == SNAPPY_OK) { | |||
| 43 | decompressed_buffer = (unsigned char *)g_malloc(orig_size); | |||
| 44 | ||||
| 45 | ret = snappy_uncompress(compr_ptr, comprlen, (char*)decompressed_buffer, &orig_size); | |||
| 46 | ||||
| 47 | if (ret == SNAPPY_OK) { | |||
| 48 | uncompr_tvb = tvb_new_real_data(decompressed_buffer, (uint32_t)orig_size, (uint32_t)orig_size); | |||
| ||||
| 49 | tvb_set_free_cb(uncompr_tvb, g_free); | |||
| 50 | } else { | |||
| 51 | g_free(decompressed_buffer)(__builtin_object_size ((decompressed_buffer), 0) != ((size_t ) - 1)) ? g_free_sized (decompressed_buffer, __builtin_object_size ((decompressed_buffer), 0)) : (g_free) (decompressed_buffer); | |||
| 52 | } | |||
| 53 | } | |||
| 54 | ||||
| 55 | return uncompr_tvb; | |||
| 56 | } | |||
| 57 | #else | |||
| 58 | tvbuff_t * | |||
| 59 | tvb_uncompress_snappy(tvbuff_t *tvb _U___attribute__((unused)), const unsigned offset _U___attribute__((unused)), unsigned comprlen _U___attribute__((unused))) | |||
| 60 | { | |||
| 61 | return NULL((void*)0); | |||
| 62 | } | |||
| 63 | #endif | |||
| 64 | ||||
| 65 | tvbuff_t * | |||
| 66 | tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb, const unsigned offset, unsigned comprlen) | |||
| 67 | { | |||
| 68 | tvbuff_t *new_tvb = tvb_uncompress_snappy(tvb, offset, comprlen); | |||
| ||||
| 69 | if (new_tvb) | |||
| 70 | tvb_set_child_real_data_tvbuff(parent, new_tvb); | |||
| 71 | return new_tvb; | |||
| 72 | } | |||
| 73 | ||||
| 74 | /* | |||
| 75 | * Editor modelines - https://www.wireshark.org/tools/modelines.html | |||
| 76 | * | |||
| 77 | * Local variables: | |||
| 78 | * c-basic-offset: 4 | |||
| 79 | * tab-width: 8 | |||
| 80 | * indent-tabs-mode: nil | |||
| 81 | * End: | |||
| 82 | * | |||
| 83 | * vi: set shiftwidth=4 tabstop=8 expandtab: | |||
| 84 | * :indentSize=4:tabSize=8:noTabs=true: | |||
| 85 | */ |