diff options
Diffstat (limited to 'src/libnpass/libnpass.c')
-rw-r--r-- | src/libnpass/libnpass.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c index b7a0ded..6618385 100644 --- a/src/libnpass/libnpass.c +++ b/src/libnpass/libnpass.c @@ -55,8 +55,8 @@ static int set_pass_dir(void) if (env) { r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env, ".password-store"); - if ((size_t)r > sizeof(pass_dir)) - err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r > sizeof(pass_dir)) + err_ret(PASS_STORE_INV, "failed to build path"); r = stat(pass_dir, &statbuf); if (!r) @@ -67,8 +67,8 @@ static int set_pass_dir(void) if (env) { r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s", env, DEF_PASS_DIR); - if ((size_t)r > sizeof(pass_dir)) - err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r > sizeof(pass_dir)) + err_ret(PASS_STORE_INV, "failed to build path"); return 0; } @@ -76,8 +76,8 @@ static int set_pass_dir(void) if (env) { r = snprintf(pass_dir, sizeof(pass_dir), "%s/%s/%s", env, ".local/share", DEF_PASS_DIR); - if ((size_t)r > sizeof(pass_dir)) - err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r > sizeof(pass_dir)) + err_ret(PASS_STORE_INV, "failed to build path"); return 0; } @@ -132,15 +132,15 @@ pass_store_t pass_store_type(const char *spath) r = snprintf(abs_path, sizeof(abs_path), "%s/%s", pass_dir, (spath) ? spath : ""); - if (r >= (int)sizeof(abs_path)) - err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(abs_path)) + err_ret(PASS_STORE_INV, "failed to build path"); r = stat(abs_path, &sbuf); if (!r && (sbuf.st_mode & S_IFMT) == S_IFDIR) return PASS_STORE_DIR; r = snprintf(abs_path, sizeof(abs_path), "%s/%s.gpg", pass_dir, spath); - if (r >= (int)sizeof(abs_path)) - err_ret(PASS_STORE_INV, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(abs_path)) + err_ret(PASS_STORE_INV, "failed to build path"); r = stat(abs_path, &sbuf); if (r) err_ret(PASS_STORE_INV, "%s", strerror(errno)); @@ -167,8 +167,8 @@ DIR *openstore(const char *spath) if (spath) { r = snprintf(abs_path, sizeof(abs_path), "%s/%s", pass_dir, spath); - if (r >= (int)sizeof(abs_path)) - err_ret(NULL, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(abs_path)) + err_ret(NULL, "failed to build path"); path = abs_path; } else { @@ -274,8 +274,8 @@ int pass_init(const char *fpr) r = snprintf(gpg_id_path, sizeof(gpg_id_path), "%s/%s", pass_dir, ".gpg-id"); - if (r > (int)sizeof(gpg_id_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(gpg_id_path)) + err_ret(1, "failed to build path"); gpg_id = fopen(gpg_id_path, "w"); if (!gpg_id) @@ -304,8 +304,8 @@ int pass_cat(FILE *out, const char *path) err_ret(1, "PASSWORD_STORE_DIR not set"); r = snprintf(pass_path, sizeof(pass_path), "%s/%s.gpg", pass_dir, path); - if (r >= (int)sizeof(pass_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(pass_path)) + err_ret(1, "failed to build path"); r = gpg_decrypt(out, pass_path); return r; @@ -372,8 +372,8 @@ int pass_add(const char *path, const char *pass, size_t n) r = snprintf(gpg_id_path, sizeof(gpg_id_path), "%s/%s", pass_dir, ".gpg-id"); - if (r > (int)sizeof(gpg_id_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(gpg_id_path)) + err_ret(1, "failed to build path"); gpg_id = fopen(gpg_id_path, "r"); if (!gpg_id) @@ -391,8 +391,8 @@ int pass_add(const char *path, const char *pass, size_t n) /* TODO: guard against .*\.gpg\.gpg[/$] */ r = snprintf(pass_path, sizeof(pass_path), "%s/%s.gpg", pass_dir, path); - if (r > (int)sizeof(pass_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(pass_path)) + err_ret(1, "failed to build path"); rc = strdup(pass_path); if (!rc) @@ -424,12 +424,12 @@ int pass_rm(const char *path) err_ret(1, "PASSWORD_STORE_DIR not set"); r = snprintf(gpg_path, sizeof(gpg_path), "%s.gpg", path); - if (r > (int)sizeof(gpg_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(gpg_path)) + err_ret(1, "failed to build path"); r = snprintf(abs_path, sizeof(gpg_path), "%s/%s", pass_dir, gpg_path); - if (r > (int)sizeof(abs_path)) - err_ret(1, "path exceeded PATH_MAX"); + if (r < 0 || (size_t)r >= sizeof(abs_path)) + err_ret(1, "failed to build path"); /* TODO: guard against .*\.gpg\.gpg[/$] */ r = unlink(abs_path); |