From c48cedd0f49b020fdd8f208dc95aee5696a8a4b0 Mon Sep 17 00:00:00 2001 From: thorpej Date: Fri, 28 Jul 2000 19:19:23 +0000 Subject: [PATCH] Filter out non-alpha-numeric characters from the default seed. No point in generating one that skey(1) will reject. --- usr.bin/skeyinit/skeyinit.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/usr.bin/skeyinit/skeyinit.c b/usr.bin/skeyinit/skeyinit.c index 9bc2b961f0d3..13250aa552b2 100644 --- a/usr.bin/skeyinit/skeyinit.c +++ b/usr.bin/skeyinit/skeyinit.c @@ -1,4 +1,4 @@ -/* $NetBSD: skeyinit.c,v 1.13 2000/07/07 00:18:29 mjl Exp $ */ +/* $NetBSD: skeyinit.c,v 1.14 2000/07/28 19:19:23 thorpej Exp $ */ /* S/KEY v1.1b (skeyinit.c) * @@ -58,7 +58,20 @@ int main(int argc, char **argv) if (gethostname(hostname, sizeof(hostname)) < 0) err(1, "gethostname"); - (void)strncpy(defaultseed, hostname, sizeof(defaultseed)- 1); + + /* + * Copy the hostname into the default seed, eliminating any + * non alpha-numeric characters. + */ + for (i = 0, l = 0; l < sizeof(defaultseed); i++) { + if (hostname[i] == '\0') { + defaultseed[l] = hostname[i]; + break; + } + if (isalnum(hostname[i])) + defaultseed[l++] = hostname[i]; + } + defaultseed[SKEY_NAMELEN] = '\0'; (void)time(&now); (void)sprintf(tbuf, "%05ld", (long) (now % 100000));