Skip to content

Commit bad2bd1

Browse files
committed
sudo_uuid_create: Convert 16 and 32-bit fields to network byte order.
Fixes a problem where the version and variant were not being parsed correctly (since they were set in host byte order).
1 parent 5c16648 commit bad2bd1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/util/regress/uuid/uuid_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ main(int argc, char *argv[])
7575

7676
/* Do 16 passes. */
7777
for (ntests = 0; ntests < 16; ntests++) {
78+
uint16_t time_hi_and_version;
7879
unsigned char uuid_buf[16];
7980
char uuid_str[37];
8081

@@ -93,8 +94,9 @@ main(int argc, char *argv[])
9394
}
9495

9596
/* Version: bits 12-15 are 0010. */
96-
if ((uuid.id.time_hi_and_version & 0xf000) != 0x4000) {
97-
sudo_warnx("bad version: 0x%x", uuid.id.time_hi_and_version & 0xf000);
97+
time_hi_and_version = ntohs(uuid.id.time_hi_and_version);
98+
if ((time_hi_and_version & 0xf000) != 0x4000) {
99+
sudo_warnx("bad version: 0x%x", (unsigned int)time_hi_and_version);
98100
errors++;
99101
continue;
100102
}

lib/util/uuid.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ sudo_uuid_create_v1(unsigned char uuid_out[restrict static 16])
5959
uuid.clock_seq_hi_and_reserved &= 0x3f;
6060
uuid.clock_seq_hi_and_reserved |= 0x80;
6161

62+
/* Convert 16 and 32-bit fields to network byte order. */
63+
uuid.time_low = ntohl(uuid.time_low);
64+
uuid.time_mid = ntohs(uuid.time_mid);
65+
uuid.time_hi_and_version = ntohs(uuid.time_hi_and_version);
66+
6267
memcpy(uuid_out, &uuid, 16);
6368
}
6469

0 commit comments

Comments
 (0)