Hi,
I was looking at the recently imported uuid interface in libc and
noticed the encode functions are broken. In particular, this pattern:
uint8_t *p = buf;
p[0] = htobe32(uuid->time_low);
p[4] = htobe16(uuid->time_mid);
p[6] = htobe16(uuid->time_hi_and_version);
The intention is obviously that the 32-bit and 16-bit values gets copied
to the buffer, but instead the value gets truncated. The resulting
encoded uuid will then contain unmodified bytes (likely uninitialized).
This appears to be the case in the kernel uuid code as well.
The FreeBSD and NetBSD counterparts for this code is instead using
be32enc and be16enc macros to put the bytes into the buffer and doesn't
suffer from this truncation issue.
Grepping through the tree reveals these encode functions are fortunately
not currently used. The decode functions are used though, but they don't
have this problem.
Jonas