Bug Summary

File:builds/wireshark/wireshark/epan/tvbuff_snappy.c
Warning:line 48, column 25
Potential leak of memory pointed to by 'decompressed_buffer'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name tvbuff_snappy.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-18/lib/clang/18 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan -isystem /builds/wireshark/wireshark/build/epan -isystem /usr/include/libxml2 -isystem /usr/include/lua5.4 -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -D epan_EXPORTS -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-truncation -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -ferror-limit 19 -fvisibility=hidden -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -dwarf-debug-flags /usr/lib/llvm-18/bin/clang -### --analyze -x c -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -D epan_EXPORTS -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan -isystem /builds/wireshark/wireshark/build/epan -isystem /usr/include/libxml2 -isystem /usr/include/lua5.4 -fvisibility=hidden -fexcess-precision=fast -fstrict-flex-arrays=3 -fstack-clash-protection -fcf-protection=full -D _GLIBCXX_ASSERTIONS -fstack-protector-strong -fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -fexceptions -Wno-format-truncation -Wno-format-nonliteral -fdiagnostics-color=always -Wno-pointer-sign -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -std=gnu11 -fPIC /builds/wireshark/wireshark/epan/tvbuff_snappy.c -o /builds/wireshark/wireshark/sbout/2024-11-20-100252-3912-1 -Xclang -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2024-11-20-100252-3912-1 -x c /builds/wireshark/wireshark/epan/tvbuff_snappy.c
1/* tvbuff_snappy.c
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
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
26tvbuff_t *
27tvb_uncompress_snappy(tvbuff_t *tvb, const int offset, int 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)) {
2
Assuming 'tvb' is not equal to NULL
3
Assuming 'comprlen' is > 0
4
Assuming the condition is false
5
Taking false branch
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) {
6
Assuming 'ret' is equal to SNAPPY_OK
7
Taking true branch
43 decompressed_buffer = (unsigned char *)g_malloc(orig_size);
8
Memory is allocated
44
45 ret = snappy_uncompress(compr_ptr, comprlen, decompressed_buffer, &orig_size);
46
47 if (ret == SNAPPY_OK) {
9
Assuming 'ret' is equal to SNAPPY_OK
10
Taking true branch
48 uncompr_tvb = tvb_new_real_data(decompressed_buffer, (uint32_t)orig_size, (uint32_t)orig_size);
11
Potential leak of memory pointed to by 'decompressed_buffer'
49 tvb_set_free_cb(uncompr_tvb, g_free);
50 } else {
51 g_free(decompressed_buffer);
52 }
53 }
54
55 return uncompr_tvb;
56}
57#else
58tvbuff_t *
59tvb_uncompress_snappy(tvbuff_t *tvb _U___attribute__((unused)), const int offset _U___attribute__((unused)), int comprlen _U___attribute__((unused)))
60{
61 return NULL((void*)0);
62}
63#endif
64
65tvbuff_t *
66tvb_child_uncompress_snappy(tvbuff_t *parent, tvbuff_t *tvb, const int offset, int comprlen)
67{
68 tvbuff_t *new_tvb = tvb_uncompress_snappy(tvb, offset, comprlen);
1
Calling 'tvb_uncompress_snappy'
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 */