summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-05-27 03:19:16 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-05-27 03:19:16 +0000
commited231d4ce45c6dbd5b1506dcbd9c85d1cb521ce0 (patch)
tree53a703221c8ad2fa332970e51336d391e0c62990 /sbin
parent6bf4b65dcca0e49217b928e13a995c04c5bf2e61 (diff)
Prevent buf[-1] access if strlen(buf) == 0.
Simplify some if-else statements while here. OK grunk@ and tedu@.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/mount_vnd/mount_vnd.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/sbin/mount_vnd/mount_vnd.c b/sbin/mount_vnd/mount_vnd.c
index 19239cbbe7d..4de5a76565c 100644
--- a/sbin/mount_vnd/mount_vnd.c
+++ b/sbin/mount_vnd/mount_vnd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mount_vnd.c,v 1.1 2007/05/26 03:37:45 grunk Exp $ */
+/* $OpenBSD: mount_vnd.c,v 1.2 2007/05/27 03:19:15 ray Exp $ */
/*
* Copyright (c) 1993 University of Utah.
* Copyright (c) 1990, 1993
@@ -189,16 +189,13 @@ get_pkcs_key(char *arg, char *saltopt)
printf("Salt file: ");
fflush(stdout);
saltfile = fgets(saltfilebuf, sizeof(saltfilebuf), stdin);
+ if (saltfile)
+ saltfile[strcspn(saltfile, "\n")] = '\0';
}
- if (!saltfile || saltfile[0] == '\n') {
+ if (!saltfile || saltfile[0] == '\0') {
warnx("Skipping salt file, insecure");
- saltfile = NULL;
+ memset(saltbuf, 0, sizeof(saltbuf));
} else {
- size_t len = strlen(saltfile);
- if (saltfile[len - 1] == '\n')
- saltfile[len - 1] = 0;
- }
- if (saltfile) {
int fd;
fd = open(saltfile, O_RDONLY);
@@ -223,8 +220,6 @@ get_pkcs_key(char *arg, char *saltopt)
err(1, "Unable to read salt file: '%s'", saltfile);
}
close(fd);
- } else {
- memset(saltbuf, 0, sizeof(saltbuf));
}
if (pkcs5_pbkdf2((u_int8_t**)&key, BLF_MAXUTILIZED, keybuf,
sizeof(keybuf), saltbuf, sizeof(saltbuf), rounds, 0))