Skip to content

Commit 2d9ae2f

Browse files
committed
fix ubsan warning about shifting signed numbers
1 parent b9d6a52 commit 2d9ae2f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/protocols/der/encode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static ssize_t fr_der_encode_integer(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, UN
161161
{
162162
fr_dbuff_t our_dbuff = FR_DBUFF(dbuff);
163163
fr_pair_t const *vp;
164-
int64_t value;
164+
uint64_t value;
165165
uint8_t first_octet = 0;
166166
size_t i, len;
167167

@@ -183,7 +183,13 @@ static ssize_t fr_der_encode_integer(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, UN
183183
* second octet, followed by bits 8 to 1 of each octet in turn up to and including the last octet of
184184
* the contents octets.
185185
*/
186-
value = vp->vp_int64;
186+
187+
/*
188+
* Yes, the type is FR_TYPE_INT64. But we encode the
189+
* data as-is, without caring about things like signed
190+
* math.
191+
*/
192+
value = vp->vp_uint64;
187193

188194
for (i = 0, len = 0; i < sizeof(value); i++) {
189195
uint8_t byte = (value >> 56) & 0xff;

0 commit comments

Comments
 (0)