Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tang-gen: endless loop if dbdir doesn't exist or no write access #1

Closed
frasertweedale opened this issue Dec 17, 2015 · 1 comment
Closed

Comments

@frasertweedale
Copy link
Contributor

This do-while in tang-gen.c is problematic. I'm not sure why loop is needed but
either existance/access checks are needed or, as a last resort, bail out after
a set number of loops.

Happy to patch this myself but needed to find out why the do-while is there
first :)

} else {
    do {
        r = keyfilegen(dbdir, filename);
        if (r != 0)
            error(EXIT_FAILURE, r, "Error generating keyfile name");

        file = fopen(filename, "wx");
    } while (!file);
}   
@npmccallum
Copy link
Contributor

The loop is there to catch random name collisions (unlikely, but a possibility). keyfilegen() creates a random filename and fopen(filename, "wx") creates the file with that name. If it fails, it may indicate a name collision. Maybe something like:
while (!file && errno == EEXIST)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants