kumquat-buildroot/package/mini-snmpd/0001-Prepend-zero-byte-before-unsigned-integers.patch

32 lines
814 B
Diff
Raw Normal View History

From 949ae648bf7c654b8fae607a0988bfa672607156 Mon Sep 17 00:00:00 2001
From: Patrick Rauscher <prauscher@prauscher.de>
Date: Fri, 18 Aug 2017 17:31:23 +0200
Subject: [PATCH] Prepend zero-byte before unsigned integers
fixes #8
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>
---
mib.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mib.c b/mib.c
index 7d2e513..a9ffbe2 100644
--- a/mib.c
+++ b/mib.c
@@ -207,6 +207,11 @@ static int encode_unsigned(data_t *data, int type, unsigned int ticks_value)
else
length = 1;
+ /* check if the integer could be interpreted negative during a signed decode and prepend a zero-byte if necessary */
+ if ((ticks_value >> (8 * (length - 1))) & 0x80) {
+ length++;
+ }
+
*buffer++ = type;
*buffer++ = length;
while (length--)
--
2.13.2