benasher44/uuid

Incorrect UUID generation when system calls fail on Linux

Opened this issue · 2 comments

Trivial example:

fun main(args: Array<String>) {
    while (true) {
        val res = open("/dev/zero", O_RDONLY)
        // out of fds
        if (res == -1 && errno == EMFILE) break
    }

    val uuid = uuid4()
    println(uuid.bytes.contentToString())
}

Output:

> Task :runReleaseExecutableLinuxX64
[0, 0, 0, 0, 0, 0, 64, 0, -128, 0, 0, 0, 0, 0, 0, 0]

This creates an arbitrary EMFILE error (which is very possible given the nature of K/N), but it could happen with something like EINTR if you're unlucky and a user provides a bad signal handler.

Thanks for filing and flagging this! Mind having a look at #108? If that looks alright, I can get a new version out with this fix soon.

0.2.3 is on its way to maven central with this fix. Thanks again for filing!