From: beck Date: Mon, 12 May 2014 08:47:37 +0000 (+0000) Subject: Make ifconfig do something intelligent based on the required length of X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=98fdf12bb098007c7562cdec56a176847c3b8616;p=openbsd Make ifconfig do something intelligent based on the required length of WEP keys rather then being silently dumb, so when using WEP: 1) If the key is a plausible size try to use it. 2) If they key would be a plausible size with '0x' in front of it, add that. 3) If the key is not a plausible size, emit a warning and do not try to use it. ok sthen@ --- diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index d2ea3790ab0..764db00c75b 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.282 2014/03/05 20:46:50 tedu Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.283 2014/05/12 08:47:37 beck Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -1576,8 +1576,40 @@ setifnwkey(const char *val, int d) return; } } else { + /* + * length of each key must be either a 5 + * character ASCII string or 10 hex digits for + * 40 bit encryption, or 13 character ASCII + * string or 26 hex digits for 128 bit + * encryption. + */ + int j; + char *tmp = NULL; + size_t vlen = strlen(val); + switch(vlen) { + case 10: + case 26: + /* 0x must be missing for these lengths */ + j = asprintf(&tmp, "0x%s", val); + if (j == -1) { + warnx("malloc failed"); + return; + } + val = tmp; + break; + case 12: + case 28: + case 5: + case 13: + /* 0xkey or string case - all is ok */ + break; + default: + warnx("Invalid WEP key length"); + return; + } len = sizeof(keybuf[0]); val = get_string(val, NULL, keybuf[0], &len); + free(tmp); if (val == NULL) return; nwkey.i_key[0].i_keylen = len;