X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-id128%2Fsd-id128.c;h=c876f6e381f90d1f48962cc366a909c5348d2c0c;hb=f7340ab269828d917cd1281e33e6dd4fdfee67b3;hp=9ee40ab91eaaee64a3f13dc61dc354bc8de26400;hpb=be12791331b9b64867b5aa4b13df88c1a2b7e2a1;p=elogind.git diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 9ee40ab91..c876f6e38 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -183,11 +183,14 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { for (j = 0, p = buf; j < 16; j++) { int a, b; - if (p >= buf + k) + if (p >= buf + k - 1) return -EIO; - if (*p == '-') + if (*p == '-') { p++; + if (p >= buf + k - 1) + return -EIO; + } a = unhexchar(p[0]); b = unhexchar(p[1]); @@ -208,26 +211,18 @@ _public_ int sd_id128_get_boot(sd_id128_t *ret) { } _public_ int sd_id128_randomize(sd_id128_t *ret) { - _cleanup_close_ int fd = -1; sd_id128_t t; - ssize_t k; + int r; assert_return(ret, -EINVAL); - fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY); - if (fd < 0) - return -errno; - - k = loop_read(fd, &t, 16, false); - if (k < 0) - return (int) k; - - if (k != 16) - return -EIO; + r = dev_urandom(&t, sizeof(t)); + if (r < 0) + return r; /* Turn this into a valid v4 UUID, to be nice. Note that we * only guarantee this for newly generated UUIDs, not for - * pre-existing ones.*/ + * pre-existing ones. */ *ret = make_v4_uuid(t); return 0;