epan: Use g_base64_decode_inplace()
Replace ws_base64_decode_inplace() with g_base64_decode_inplace() or g_base64_decode(), which was introduced in glib 2.12. The only observed difference is a need for zero-terminate the buffer after decoding. Change-Id: Ia102d0d8e9bec575ffeddf448191a3f6de9fb1ed Reviewed-on: https://code.wireshark.org/review/29382 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
42ad60896d
commit
65b342f749
1
debian/libwsutil0.symbols
vendored
1
debian/libwsutil0.symbols
vendored
@ -160,7 +160,6 @@ libwsutil.so.0 libwsutil0 #MINVER#
|
||||
ws_ascii_strnatcasecmp@Base 1.99.1
|
||||
ws_ascii_strnatcmp@Base 1.99.1
|
||||
ws_base32_decode@Base 2.3.0
|
||||
ws_base64_decode_inplace@Base 1.12.0~rc1
|
||||
ws_buffer_append@Base 1.99.0
|
||||
ws_buffer_assure_space@Base 1.99.0
|
||||
ws_buffer_free@Base 1.99.0
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <epan/proto_data.h>
|
||||
#include <epan/export_object.h>
|
||||
|
||||
#include <wsutil/base64.h>
|
||||
#include "packet-http.h"
|
||||
#include "packet-tcp.h"
|
||||
#include "packet-ssl.h"
|
||||
@ -3311,6 +3310,7 @@ check_auth_basic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value)
|
||||
const char **header;
|
||||
size_t hdrlen;
|
||||
proto_tree *hdr_tree;
|
||||
gsize len;
|
||||
|
||||
for (header = &basic_headers[0]; *header != NULL; header++) {
|
||||
hdrlen = strlen(*header);
|
||||
@ -3322,7 +3322,8 @@ check_auth_basic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value)
|
||||
hdr_tree = NULL;
|
||||
value += hdrlen;
|
||||
|
||||
ws_base64_decode_inplace(value);
|
||||
g_base64_decode_inplace(value, &len);
|
||||
value[len] = 0;
|
||||
proto_tree_add_string(hdr_tree, hf_http_basic, tvb,
|
||||
0, 0, value);
|
||||
|
||||
@ -3350,6 +3351,7 @@ check_auth_citrixbasic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value, int of
|
||||
char *data_val;
|
||||
proto_item *hidden_item;
|
||||
proto_item *pi;
|
||||
gsize len;
|
||||
|
||||
for (header = &basic_headers[0]; *header != NULL; header++) {
|
||||
hdrlen = strlen(*header);
|
||||
@ -3372,7 +3374,8 @@ check_auth_citrixbasic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value, int of
|
||||
if ( ch_ptr != NULL ) {
|
||||
data_len = (int)(ch_ptr - value + 1);
|
||||
data_val = wmem_strndup(wmem_packet_scope(), value, data_len);
|
||||
ws_base64_decode_inplace(data_val);
|
||||
g_base64_decode_inplace(data_val, &len);
|
||||
data_val[len] = 0;
|
||||
pi = proto_tree_add_string(hdr_tree, hf_http_citrix_user, tvb,
|
||||
offset , data_len - 1, data_val);
|
||||
PROTO_ITEM_SET_GENERATED(pi);
|
||||
@ -3387,7 +3390,8 @@ check_auth_citrixbasic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value, int of
|
||||
if ( ch_ptr != NULL ) {
|
||||
data_len = (int)(ch_ptr - value + 1);
|
||||
data_val = wmem_strndup(wmem_packet_scope(), value, data_len);
|
||||
ws_base64_decode_inplace(data_val);
|
||||
g_base64_decode_inplace(data_val, &len);
|
||||
data_val[len] = 0;
|
||||
pi = proto_tree_add_string(hdr_tree, hf_http_citrix_domain, tvb,
|
||||
offset, data_len - 1, data_val);
|
||||
PROTO_ITEM_SET_GENERATED(pi);
|
||||
@ -3402,7 +3406,8 @@ check_auth_citrixbasic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value, int of
|
||||
if ( ch_ptr != NULL ) {
|
||||
data_len = (int)(ch_ptr - value + 1);
|
||||
data_val = wmem_strndup(wmem_packet_scope(), value, data_len);
|
||||
ws_base64_decode_inplace(data_val);
|
||||
g_base64_decode_inplace(data_val, &len);
|
||||
data_val[len] = 0;
|
||||
pi = proto_tree_add_string(hdr_tree, hf_http_citrix_passwd, tvb,
|
||||
offset, data_len - 1, data_val);
|
||||
PROTO_ITEM_SET_GENERATED(pi);
|
||||
@ -3417,7 +3422,8 @@ check_auth_citrixbasic(proto_item *hdr_item, tvbuff_t *tvb, gchar *value, int of
|
||||
if ( ch_ptr != NULL ) {
|
||||
data_len = (int)(ch_ptr - value + 1);
|
||||
data_val = wmem_strndup(wmem_packet_scope(), value, data_len);
|
||||
ws_base64_decode_inplace(data_val);
|
||||
g_base64_decode_inplace(data_val, &len);
|
||||
data_val[len] = 0;
|
||||
pi = proto_tree_add_string(hdr_tree, hf_http_citrix_session, tvb,
|
||||
offset, data_len - 1, data_val);
|
||||
PROTO_ITEM_SET_GENERATED(pi);
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <epan/reassemble.h>
|
||||
#include <epan/proto_data.h>
|
||||
|
||||
#include <wsutil/base64.h>
|
||||
#include <wsutil/str_util.h>
|
||||
#include "packet-ssl.h"
|
||||
#include "packet-ssl-utils.h"
|
||||
@ -310,10 +309,13 @@ decode_plain_auth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
||||
gint length_pass;
|
||||
guint8 *decrypt = NULL;
|
||||
proto_item *ti;
|
||||
gsize len;
|
||||
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, a_offset, a_linelen, ENC_ASCII);
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
returncode = (gint)ws_base64_decode_inplace(decrypt);
|
||||
g_base64_decode_inplace(decrypt, &len);
|
||||
decrypt[len] = 0;
|
||||
returncode = (gint)len;
|
||||
if (returncode) {
|
||||
length_user1 = (gint)strlen(decrypt);
|
||||
if (returncode >= (length_user1 + 1)) {
|
||||
@ -364,7 +366,7 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
fragment_head *frag_msg = NULL;
|
||||
tvbuff_t *next_tvb;
|
||||
guint8 *decrypt = NULL;
|
||||
size_t decrypt_len = 0;
|
||||
gsize decrypt_len = 0;
|
||||
guint8 *base64_string = NULL;
|
||||
guint8 line_code[3];
|
||||
|
||||
@ -555,7 +557,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
((session_state->last_auth_frame == 0) || (pinfo->num <= session_state->last_auth_frame))) {
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
if ((smtp_auth_parameter_decoding_enabled) &&
|
||||
((decrypt_len = ws_base64_decode_inplace(decrypt)) > 0)) {
|
||||
(g_base64_decode_inplace(decrypt, &decrypt_len)) &&
|
||||
(decrypt_len > 0)) {
|
||||
decrypt[decrypt_len] = 0;
|
||||
line = decrypt;
|
||||
linelen = (int)decrypt_len;
|
||||
} else {
|
||||
@ -819,7 +823,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) == 0) {
|
||||
g_base64_decode_inplace(decrypt, &decrypt_len);
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (decrypt_len == 0) {
|
||||
/* Go back to the original string */
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
@ -835,7 +841,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) == 0) {
|
||||
g_base64_decode_inplace(decrypt, &decrypt_len);
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (decrypt_len == 0) {
|
||||
/* Go back to the original string */
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
@ -849,7 +857,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) == 0) {
|
||||
g_base64_decode_inplace(decrypt, &decrypt_len);
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (decrypt_len == 0) {
|
||||
/* Go back to the original string */
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset, linelen, ENC_ASCII);
|
||||
decrypt_len = linelen;
|
||||
@ -896,7 +906,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset + 11, linelen - 11, ENC_ASCII);
|
||||
decrypt_len = linelen - 11;
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) == 0) {
|
||||
g_base64_decode_inplace(decrypt, &decrypt_len);
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (decrypt_len == 0) {
|
||||
/* Go back to the original string */
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset + 11, linelen - 11, ENC_ASCII);
|
||||
decrypt_len = linelen - 11;
|
||||
@ -916,7 +928,9 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset + 10, linelen - 10, ENC_ASCII);
|
||||
decrypt_len = linelen - 10;
|
||||
if (smtp_auth_parameter_decoding_enabled) {
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) == 0) {
|
||||
g_base64_decode_inplace(decrypt, &decrypt_len);
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (decrypt_len == 0) {
|
||||
/* Go back to the original string */
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset + 10, linelen - 10, ENC_ASCII);
|
||||
decrypt_len = linelen - 10;
|
||||
@ -1099,7 +1113,8 @@ dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_
|
||||
if (linelen >= 4) {
|
||||
if ((smtp_auth_parameter_decoding_enabled) && (code == 334)) {
|
||||
decrypt = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 4, linelen - 4, ENC_ASCII);
|
||||
if ((decrypt_len = ws_base64_decode_inplace(decrypt)) > 0) {
|
||||
if ((g_base64_decode_inplace(decrypt, &decrypt_len)) && decrypt_len > 0) {
|
||||
decrypt[decrypt_len] = 0;
|
||||
if (g_ascii_strncasecmp(decrypt, "NTLMSSP", 7) == 0) {
|
||||
base64_string = tvb_get_string_enc(wmem_packet_scope(), tvb, loffset + 4, linelen - 4, ENC_ASCII);
|
||||
col_append_fstr(pinfo->cinfo, COL_INFO, "%d ", code);
|
||||
@ -1288,8 +1303,8 @@ proto_register_smtp(void)
|
||||
&smtp_data_desegment);
|
||||
|
||||
prefs_register_bool_preference(smtp_module, "decryption",
|
||||
"Decode base-64-encoded AUTH parameters",
|
||||
"Whether the SMTP dissector should decode base-64-encoded AUTH parameters",
|
||||
"Decode Base64 encoded AUTH parameters",
|
||||
"Whether the SMTP dissector should decode Base64 encoded AUTH parameters",
|
||||
&smtp_auth_parameter_decoding_enabled);
|
||||
}
|
||||
|
||||
|
@ -13,17 +13,16 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include <epan/tvbuff.h>
|
||||
#include <wsutil/base64.h>
|
||||
|
||||
tvbuff_t *
|
||||
base64_to_tvb(tvbuff_t *parent, const char *base64)
|
||||
{
|
||||
tvbuff_t *tvb;
|
||||
char *data = g_strdup(base64);
|
||||
gint len;
|
||||
char *data;
|
||||
gsize len;
|
||||
|
||||
len = (gint) ws_base64_decode_inplace(data);
|
||||
tvb = tvb_new_child_real_data(parent, (const guint8 *)data, len, len);
|
||||
data = g_base64_decode(base64, &len);
|
||||
tvb = tvb_new_child_real_data(parent, (const guint8 *)data, (gint)len, (gint)len);
|
||||
|
||||
tvb_set_free_cb(tvb, g_free);
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "wslua.h"
|
||||
#include "wsutil/base64.h"
|
||||
|
||||
|
||||
/* WSLUA_CONTINUE_MODULE Tvb */
|
||||
@ -243,22 +242,22 @@ WSLUA_METHOD ByteArray_subset(lua_State* L) {
|
||||
}
|
||||
|
||||
WSLUA_METHOD ByteArray_base64_decode(lua_State* L) {
|
||||
/* Obtain a base64 decoded `ByteArray`.
|
||||
/* Obtain a Base64 decoded `ByteArray`.
|
||||
|
||||
@since 1.11.3
|
||||
*/
|
||||
ByteArray ba = checkByteArray(L,1);
|
||||
ByteArray ba2;
|
||||
gchar *data;
|
||||
size_t len;
|
||||
gsize len;
|
||||
|
||||
ba2 = g_byte_array_new();
|
||||
data = (gchar*)g_malloc (ba->len + 1);
|
||||
data = (gchar*)g_malloc(ba->len + 1);
|
||||
memcpy(data, ba->data, ba->len);
|
||||
data[ba->len] = '\0';
|
||||
|
||||
len = ws_base64_decode_inplace(data);
|
||||
g_byte_array_append(ba2,data,(int)len);
|
||||
g_base64_decode_inplace(data, &len);
|
||||
g_byte_array_append(ba2, data, (int)len);
|
||||
g_free(data);
|
||||
|
||||
pushByteArray(L,ba2);
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#include "epan/charsets.h"
|
||||
|
||||
#include "wsutil/base64.h"
|
||||
#include "wsutil/utf8_entities.h"
|
||||
|
||||
#include <QAction>
|
||||
@ -487,6 +486,7 @@ void ShowPacketBytesDialog::updateFieldBytes(bool initialization)
|
||||
int start = finfo_->start + start_;
|
||||
int length = end_ - start_;
|
||||
const guint8 *bytes;
|
||||
gsize new_length;
|
||||
|
||||
if (!finfo_->ds_tvb)
|
||||
return;
|
||||
@ -502,8 +502,8 @@ void ShowPacketBytesDialog::updateFieldBytes(bool initialization)
|
||||
{
|
||||
bytes = tvb_get_ptr(finfo_->ds_tvb, start, -1);
|
||||
field_bytes_ = QByteArray((const char *)bytes, length);
|
||||
size_t len = ws_base64_decode_inplace(field_bytes_.data());
|
||||
field_bytes_.resize((int)len);
|
||||
g_base64_decode_inplace(field_bytes_.data(), &new_length);
|
||||
field_bytes_.resize((int)new_length);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ add_definitions(-DEXTCAP_DIR=\"${CMAKE_INSTALL_PREFIX}/${EXTCAP_INSTALL_LIBDIR}\
|
||||
set(WSUTIL_PUBLIC_HEADERS
|
||||
adler32.h
|
||||
base32.h
|
||||
base64.h
|
||||
bits_count_ones.h
|
||||
bits_ctz.h
|
||||
bitswap.h
|
||||
@ -77,7 +76,6 @@ set(WSUTIL_PUBLIC_HEADERS
|
||||
set(WSUTIL_COMMON_FILES
|
||||
adler32.c
|
||||
base32.c
|
||||
base64.c
|
||||
bitswap.c
|
||||
buffer.c
|
||||
clopts_common.c
|
||||
|
@ -1,66 +0,0 @@
|
||||
/* base64.c
|
||||
* Base-64 conversion
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "base64.h"
|
||||
|
||||
/* Decode a base64 string in-place - simple and slow algorithm.
|
||||
Return length of result. Taken from rproxy/librsync/base64.c by
|
||||
Andrew Tridgell. */
|
||||
|
||||
size_t ws_base64_decode_inplace(char *s)
|
||||
{
|
||||
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
|
||||
int bit_offset, byte_offset, idx, i;
|
||||
unsigned char *d = (unsigned char *)s;
|
||||
char *p;
|
||||
int cr_idx;
|
||||
|
||||
/* we will allow CR and LF - but ignore them */
|
||||
cr_idx = (int)(strchr(b64, '\r') - b64);
|
||||
|
||||
i = 0;
|
||||
|
||||
while (*s && (p = strchr(b64, *s))) {
|
||||
idx = (int)(p - b64);
|
||||
if (idx < cr_idx) {
|
||||
byte_offset = (i * 6) / 8;
|
||||
bit_offset = (i * 6) % 8;
|
||||
d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1);
|
||||
if (bit_offset < 3) {
|
||||
d[byte_offset] |= (idx << (2 - bit_offset));
|
||||
} else {
|
||||
d[byte_offset] |= (idx >> (bit_offset - 2));
|
||||
d[byte_offset + 1] = 0;
|
||||
d[byte_offset + 1] |= (idx << (8 - (bit_offset - 2))) & 0xFF;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
d[i*3/4] = 0;
|
||||
return i*3/4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
||||
*
|
||||
* Local variables:
|
||||
* c-basic-offset: 8
|
||||
* tab-width: 8
|
||||
* indent-tabs-mode: t
|
||||
* End:
|
||||
*
|
||||
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
||||
* :indentSize=8:tabSize=8:noTabs=false:
|
||||
*/
|
@ -1,27 +0,0 @@
|
||||
/* base64.h
|
||||
* Base-64 conversion
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#ifndef __BASE64_H__
|
||||
#define __BASE64_H__
|
||||
|
||||
#include "ws_symbol_export.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* In-place decoding of a base64 string. Resulting string is NULL terminated */
|
||||
WS_DLL_PUBLIC
|
||||
size_t ws_base64_decode_inplace(char *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __BASE64_H__ */
|
Loading…
x
Reference in New Issue
Block a user