Add some validity checks for seed and password.

This commit is contained in:
mjl 2000-07-07 15:45:00 +00:00
parent c9545d3e5d
commit 9493ab0864
1 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: skey.c,v 1.10 2000/07/07 15:18:14 mjl Exp $ */ /* $NetBSD: skey.c,v 1.11 2000/07/07 15:45:00 mjl Exp $ */
/* /*
* S/KEY v1.1b (skey.c) * S/KEY v1.1b (skey.c)
@ -23,9 +23,10 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: skey.c,v 1.10 2000/07/07 15:18:14 mjl Exp $"); __RCSID("$NetBSD: skey.c,v 1.11 2000/07/07 15:45:00 mjl Exp $");
#endif #endif
#include <ctype.h>
#include <err.h> #include <err.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
@ -42,7 +43,7 @@ main(int argc, char **argv)
{ {
int n, cnt, i, pass = 0, hexmode = 0; int n, cnt, i, pass = 0, hexmode = 0;
char passwd[SKEY_MAX_PW_LEN+1], key[SKEY_BINKEY_SIZE]; char passwd[SKEY_MAX_PW_LEN+1], key[SKEY_BINKEY_SIZE];
char buf[33], *seed, *slash; char buf[33], *seed, *slash, *t;
cnt = 1; cnt = 1;
@ -101,6 +102,14 @@ main(int argc, char **argv)
seed = argv[++optind]; seed = argv[++optind];
} }
for(t = seed; *t; t++) {
if(!isalnum(*t))
errx(1, "seed must be alphanumeric");
}
if(!*seed || strlen(seed) > SKEY_MAX_SEED_LEN)
errx(1, "seed must be between 1 and %d long", SKEY_MAX_SEED_LEN);
/* Get user's secret password */ /* Get user's secret password */
if (!pass) { if (!pass) {
(void)fputs("Reminder - Do not use this program while " (void)fputs("Reminder - Do not use this program while "
@ -111,6 +120,9 @@ main(int argc, char **argv)
exit(1); exit(1);
} }
if(strlen(passwd) < SKEY_MIN_PW_LEN)
errx(1, "password must be at least %d long", SKEY_MIN_PW_LEN);
/* Crunch seed and password into starting key */ /* Crunch seed and password into starting key */
if (keycrunch(key, seed, passwd) != 0) if (keycrunch(key, seed, passwd) != 0)
errx(1, "key crunch failed"); errx(1, "key crunch failed");