diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-05-27 03:19:16 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-05-27 03:19:16 +0000 |
commit | ed231d4ce45c6dbd5b1506dcbd9c85d1cb521ce0 (patch) | |
tree | 53a703221c8ad2fa332970e51336d391e0c62990 | |
parent | 6bf4b65dcca0e49217b928e13a995c04c5bf2e61 (diff) |
Prevent buf[-1] access if strlen(buf) == 0.
Simplify some if-else statements while here.
OK grunk@ and tedu@.
-rw-r--r-- | sbin/mount_vnd/mount_vnd.c | 15 |
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)) |