Coverage Report

Created: 2026-08-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-smb-common.c
Line
Count
Source
1
/* packet-smb-common.c
2
 * Common routines for smb packet dissection
3
 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * Copied from packet-pop.c
10
 *
11
 * SPDX-License-Identifier: GPL-2.0-or-later
12
 */
13
14
#include "config.h"
15
16
#include <epan/packet.h>
17
#include <epan/strutil.h>
18
#include "packet-smb-common.h"
19
20
#include "packet-dns.h"
21
22
/*
23
 * Share type values - used in LANMAN and in SRVSVC.
24
 *
25
 * XXX - should we dissect share type values, at least in SRVSVC, as
26
 * a subtree with bitfields, as the 0x80000000 bit appears to be a
27
 * hidden bit, with some number of bits at the bottom being the share
28
 * type?
29
 *
30
 * Does LANMAN use that bit?
31
 */
32
const value_string share_type_vals[] = {
33
  {0, "Directory tree"},
34
  {1, "Printer queue"},
35
  {2, "Communications device"},
36
  {3, "IPC"},
37
  {0x80000000, "Hidden Directory tree"},
38
  {0x80000001, "Hidden Printer queue"},
39
  {0x80000002, "Hidden Communications device"},
40
  {0x80000003, "Hidden IPC"},
41
  {0, NULL}
42
};
43
44
int display_ms_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int hf_index, char **data)
45
0
{
46
0
  char *str;
47
0
  unsigned len;
48
49
  /* display a string from the tree and return the new offset */
50
51
  /* XXX - This should just use proto_tree_add_item_ret_string_and_length,
52
   * but we need to make sure all the hf_index are FT_STRINGZ. */
53
0
  str = (char*)tvb_get_stringz_enc(pinfo->pool, tvb, offset, &len, ENC_ASCII);
54
0
  proto_tree_add_string(tree, hf_index, tvb, offset, len, str);
55
56
  /* Return a copy of the string if requested */
57
58
0
  if (data)
59
0
    *data = str;
60
61
0
  return  offset+len;
62
0
}
63
64
65
int display_unicode_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int hf_index, char **data)
66
0
{
67
0
  char    *str;
68
0
  unsigned len;
69
70
  /* display a unicode string from the tree and return new offset */
71
0
  proto_tree_add_item_ret_display_string_and_length(tree, hf_index, tvb, offset, -1, ENC_UTF_16 | ENC_LITTLE_ENDIAN, pinfo->pool, &str, &len);
72
73
  /* Return a copy of the string if requested */
74
0
  if (data)
75
0
    *data = str;
76
77
0
  return  offset+len;
78
0
}
79
80
/* Max string length for displaying Unicode strings.  */
81
0
#define MAX_UNICODE_STR_LEN 256
82
83
int dissect_ms_compressed_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, int hf_index,
84
         const char **data)
85
0
{
86
0
  int           compr_len;
87
0
  int          str_len;
88
0
  const char   *str = NULL;
89
90
  /* The name data MUST start at offset 0 of the tvb */
91
0
  compr_len = get_dns_name(pinfo->pool, tvb, offset, MAX_UNICODE_STR_LEN+3+1, 0, &str, &str_len);
92
0
  proto_tree_add_string(tree, hf_index, tvb, offset, compr_len, format_text(pinfo->pool, str, str_len));
93
94
0
  if (data)
95
0
    *data = str;
96
97
0
  return offset + compr_len;
98
0
}
99
100
/*
101
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
102
 *
103
 * Local variables:
104
 * c-basic-offset: 8
105
 * tab-width: 8
106
 * indent-tabs-mode: t
107
 * End:
108
 *
109
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
110
 * :indentSize=8:tabSize=8:noTabs=false:
111
 */