aboutsummaryrefslogtreecommitdiff
path: root/src/libnpass
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnpass')
-rw-r--r--src/libnpass/libnpass.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c
index f62f098..779a42a 100644
--- a/src/libnpass/libnpass.c
+++ b/src/libnpass/libnpass.c
@@ -250,6 +250,8 @@ int readstore_all(const char *path, struct store **stor)
err_ret(-errno, "%s", strerror(errno));
}
}
+ if (len == 0)
+ free(*stor);
return (ret < 0) ? ret : len;
}
@@ -309,10 +311,11 @@ int pass_cat(FILE *out, const char *path)
return gpg_decrypt(out, pass_path);
}
-ssize_t pass_getpass(char **lineptr, size_t *n, FILE *stream)
+ssize_t pass_getpass(char **lineptr, FILE *stream)
{
struct termios new, old;
- int ret;
+ size_t len;
+ ssize_t ret;
ret = tcgetattr(fileno(stream), &old);
if (ret < 0)
@@ -324,17 +327,22 @@ ssize_t pass_getpass(char **lineptr, size_t *n, FILE *stream)
if (ret < 0)
err_ret(-errno, "%s", strerror(errno));
- ret = getline(lineptr, n, stream);
- if (ret > 0 && (*lineptr)[ret - 1] == '\n')
- (*lineptr)[ret - 1] = '\0';
- else if (ret < 0)
+ len = 0;
+ *lineptr = NULL;
+ ret = getline(lineptr, &len, stream);
+ if (ret < 0)
err_ret(-errno, "%s", strerror(errno));
+ else if (ret > 0 && (*lineptr)[ret - 1] == '\n')
+ (*lineptr)[--ret] = '\0';
+ len = ret;
ret = tcsetattr(fileno(stream), TCSAFLUSH, &old);
- if (ret < 0)
+ if (ret < 0) {
+ free(*lineptr);
err_ret(-errno, "%s", strerror(errno));
+ }
- return 0;
+ return len;
}
int pass_gen(pass_gen_t gen, char *pass, int len)