From d232037e18381ee483fc0fdd4715e1146c47dbc1 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 30 Oct 2024 16:55:56 +0100 Subject: [PATCH] [winpr,asn1] fix writing integers ASN1 integers are signed. --- winpr/libwinpr/utils/asn1/asn1.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/winpr/libwinpr/utils/asn1/asn1.c b/winpr/libwinpr/utils/asn1/asn1.c index 257d02ce6..e8136a2ce 100644 --- a/winpr/libwinpr/utils/asn1/asn1.c +++ b/winpr/libwinpr/utils/asn1/asn1.c @@ -538,11 +538,10 @@ static size_t asn1IntegerLen(WinPrAsn1_INTEGER value) static size_t WinPrAsn1EncIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag b, WinPrAsn1_INTEGER value) { - wStream staticS; + wStream staticS = { 0 }; wStream* s = &staticS; - size_t len = 0; - len = asn1IntegerLen(value); + const size_t len = asn1IntegerLen(value); if (!asn1_getWriteStream(enc, 1 + len, s)) return 0; @@ -551,15 +550,15 @@ static size_t WinPrAsn1EncIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag b, { case 2: Stream_Write_UINT8(s, 1); - Stream_Write_UINT8(s, value); + Stream_Write_INT8(s, value); break; case 3: Stream_Write_UINT8(s, 2); - Stream_Write_UINT16_BE(s, value); + Stream_Write_INT16_BE(s, value); break; case 5: Stream_Write_UINT8(s, 4); - Stream_Write_UINT32_BE(s, value); + Stream_Write_INT32_BE(s, value); break; } return 1 + len; @@ -578,17 +577,14 @@ size_t WinPrAsn1EncEnumerated(WinPrAsn1Encoder* enc, WinPrAsn1_ENUMERATED value) static size_t WinPrAsn1EncContextualIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag tag, WinPrAsn1_tagId tagId, WinPrAsn1_INTEGER value) { - wStream staticS; + wStream staticS = { 0 }; wStream* s = &staticS; - size_t len = 0; - size_t outLen = 0; WINPR_ASSERT(enc); WINPR_ASSERT_VALID_TAG(tagId); - len = asn1IntegerLen(value); - - outLen = 1 + lenBytes(1 + len) + (1 + len); + const size_t len = asn1IntegerLen(value); + const size_t outLen = 1 + lenBytes(1 + len) + (1 + len); if (!asn1_getWriteStream(enc, outLen, s)) return 0; @@ -600,15 +596,15 @@ static size_t WinPrAsn1EncContextualIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1 { case 2: Stream_Write_UINT8(s, 1); - Stream_Write_UINT8(s, value); + Stream_Write_INT8(s, value); break; case 3: Stream_Write_UINT8(s, 2); - Stream_Write_UINT16_BE(s, value); + Stream_Write_INT16_BE(s, value); break; case 5: Stream_Write_UINT8(s, 4); - Stream_Write_UINT32_BE(s, value); + Stream_Write_INT32_BE(s, value); break; } return outLen;