fix "new.key: Is a directory" and a memleak when generating a keypair

Test: minisign -G -p new.pub -s new.key
Expected: new.pub and new.key appears in CWD
Actual: error "new.key: Is a directory" and no keys
This commit is contained in:
Maxim Ivanov 2017-12-14 14:37:18 +02:00
parent c4cca6ef89
commit 5e81e5a3c6

View file

@ -206,7 +206,11 @@ basedir_create_useronly(const char *file)
dir = xstrdup(file);
basename = file_basename(dir);
if (basename != dir) {
if (basename == dir) {
// this is a plain file path relative to CWD
free(dir);
return 0;
} else {
dir[basename - dir - 1] = 0;
}
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
@ -217,8 +221,8 @@ basedir_create_useronly(const char *file)
if (*dir == 0 || _mkdir(dir) == 0 || errno == EEXIST) {
ret = 0;
}
free(dir);
#endif
free(dir);
return ret;
}