aboutsummaryrefslogtreecommitdiffstats
path: root/epan/tvbuff.c
diff options
context:
space:
mode:
authorBrian Sipos <brian.sipos@gmail.com>2022-10-16 17:30:19 -0400
committerAndersBroman <a.broman58@gmail.com>2022-10-19 15:27:42 +0000
commit5bb756e203539c7fd3bb6c16dd845e42a347a982 (patch)
tree87dca3b98b1766a7fae046bbffc3ec9343dd57fc /epan/tvbuff.c
parentd2e5bd80cbc5c29f6a33dc6678baeaa4fd358c64 (diff)
epan: centralize SDNV processing along other similar varint types
This avoids having general-purpose decoding happening in non-DLL-exported functions defined in a dissector for #18478, and removes unused functions and avoids duplicate decoding. This also removes unnecessary early exit conditions for #18145. Unit test cases for varint decoding are added to verify this.
Diffstat (limited to 'epan/tvbuff.c')
-rw-r--r--epan/tvbuff.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index 81502d2531..97e60b564d 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -4563,6 +4563,29 @@ tvb_get_varint(tvbuff_t *tvb, guint offset, guint maxlen, guint64 *value, const
break;
}
+ case ENC_VARINT_SDNV:
+ {
+ /* Decodes similar to protobuf but in MSByte order */
+ guint i;
+ guint64 b; /* current byte */
+
+ for (i = 0; ((i < FT_VARINT_MAX_LEN) && (i < maxlen)); ++i) {
+ b = tvb_get_guint8(tvb, offset++);
+ if ((i == 9) && (*value >= 1ul<<(64-7))) {
+ // guaranteed overflow, not valid SDNV
+ return 0;
+ }
+ *value <<= 7;
+ *value |= (b & 0x7F); /* add lower 7 bits to val */
+
+ if (b < 0x80) {
+ /* end successfully because of last byte's msb(most significant bit) is zero */
+ return i + 1;
+ }
+ }
+ break;
+ }
+
case ENC_VARINT_QUIC:
{
/* calculate variable length */