Module Name:    src
Committed By:   dyoung
Date:           Thu Jul  1 16:44:05 UTC 2010

Modified Files:
        src/sbin/ifconfig: ieee80211.c media.c parse.c parse.h util.c util.h

Log Message:
Add to the string parse object (pstr), and its constructors, a flag that
tells whether it should detect and convert to binary a hexadecimal octet
string of the form 0x0123ABab, or leave those strings undecoded.

If the argument for a 'media', 'mediamode', 'mediaopt', '-mediaopt',
'nwkey', or 'bssid' keyword is a hexadecimal octet string, do not detect
and decode it.  (Note that setifnwkey decodes hexadecimal strings on its
own.)

This fixes a bug noticed by Jim Miller where the trailing zero-octets
were discarded from hexadecimal octet-string arguments for 'nwkey'.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sbin/ifconfig/ieee80211.c
cvs rdiff -u -r1.3 -r1.4 src/sbin/ifconfig/media.c
cvs rdiff -u -r1.15 -r1.16 src/sbin/ifconfig/parse.c
cvs rdiff -u -r1.6 -r1.7 src/sbin/ifconfig/parse.h
cvs rdiff -u -r1.14 -r1.15 src/sbin/ifconfig/util.c
cvs rdiff -u -r1.8 -r1.9 src/sbin/ifconfig/util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/ifconfig/ieee80211.c
diff -u src/sbin/ifconfig/ieee80211.c:1.23 src/sbin/ifconfig/ieee80211.c:1.24
--- src/sbin/ifconfig/ieee80211.c:1.23	Sun Jan 18 00:24:29 2009
+++ src/sbin/ifconfig/ieee80211.c	Thu Jul  1 16:44:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.23 2009/01/18 00:24:29 lukem Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ieee80211.c,v 1.23 2009/01/18 00:24:29 lukem Exp $");
+__RCSID("$NetBSD: ieee80211.c,v 1.24 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -184,11 +184,11 @@
     0, INT_MAX, 10, setifpowersavesleep, "powersavesleep",
     &command_root.pb_parser);
 
-struct pstr parse_nwkey = PSTR_INITIALIZER(&parse_nwkey, "nwkey", setifnwkey,
-    "nwkey", &command_root.pb_parser);
+struct pstr parse_nwkey = PSTR_INITIALIZER1(&parse_nwkey, "nwkey", setifnwkey,
+    "nwkey", false, &command_root.pb_parser);
 
-struct pstr parse_bssid = PSTR_INITIALIZER(&parse_bssid, "bssid", setifbssid,
-    "bssid", &command_root.pb_parser);
+struct pstr parse_bssid = PSTR_INITIALIZER1(&parse_bssid, "bssid", setifbssid,
+    "bssid", false, &command_root.pb_parser);
 
 static int
 set80211(prop_dictionary_t env, uint16_t type, int16_t val, int16_t len,
@@ -375,7 +375,7 @@
 			val += 2;
 			for (i = 0; i < IEEE80211_WEP_NKID; i++) {
 				val = get_string(val, ",", keybuf[i],
-				    &nwkey.i_key[i].i_keylen);
+				    &nwkey.i_key[i].i_keylen, true);
 				if (val == NULL) {
 					errno = EINVAL;
 					return -1;
@@ -386,7 +386,7 @@
 			}
 		} else {
 			val = get_string(val, NULL, keybuf[0],
-			    &nwkey.i_key[0].i_keylen);
+			    &nwkey.i_key[0].i_keylen, true);
 			if (val == NULL) {
 				errno = EINVAL;
 				return -1;

Index: src/sbin/ifconfig/media.c
diff -u src/sbin/ifconfig/media.c:1.3 src/sbin/ifconfig/media.c:1.4
--- src/sbin/ifconfig/media.c:1.3	Tue Jul 15 21:27:58 2008
+++ src/sbin/ifconfig/media.c	Thu Jul  1 16:44:05 2010
@@ -1,6 +1,6 @@
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: media.c,v 1.3 2008/07/15 21:27:58 dyoung Exp $");
+__RCSID("$NetBSD: media.c,v 1.4 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -51,21 +51,21 @@
 static const struct ifmedia_status_description ifm_status_descriptions[] =
     IFM_STATUS_DESCRIPTIONS;
 
-static struct pstr mediamode = PSTR_INITIALIZER(&mediamode, "mediamode",
-    setmediamode, "mediamode", &command_root.pb_parser);
+static struct pstr mediamode = PSTR_INITIALIZER1(&mediamode, "mediamode",
+    setmediamode, "mediamode", false, &command_root.pb_parser);
 
 static struct pinteger mediainst = PINTEGER_INITIALIZER1(&mediainst,
     "mediainst", 0, IFM_INST_MAX, 10, setmediainst, "mediainst",
     &command_root.pb_parser);
 
-static struct pstr unmediaopt = PSTR_INITIALIZER(&unmediaopt, "-mediaopt",
-    unsetmediaopt, "unmediaopt", &command_root.pb_parser);
+static struct pstr unmediaopt = PSTR_INITIALIZER1(&unmediaopt, "-mediaopt",
+    unsetmediaopt, "unmediaopt", false, &command_root.pb_parser);
 
-static struct pstr mediaopt = PSTR_INITIALIZER(&mediaopt, "mediaopt",
-    setmediaopt, "mediaopt", &command_root.pb_parser);
+static struct pstr mediaopt = PSTR_INITIALIZER1(&mediaopt, "mediaopt",
+    setmediaopt, "mediaopt", false, &command_root.pb_parser);
 
-static struct pstr media = PSTR_INITIALIZER(&media, "media", setmedia, "media",
-    &command_root.pb_parser);
+static struct pstr media = PSTR_INITIALIZER1(&media, "media", setmedia, "media",
+    false, &command_root.pb_parser);
 
 static const struct kwinst mediakw[] = {
 	  {.k_word = "instance", .k_key = "anymedia", .k_type = KW_T_BOOL,

Index: src/sbin/ifconfig/parse.c
diff -u src/sbin/ifconfig/parse.c:1.15 src/sbin/ifconfig/parse.c:1.16
--- src/sbin/ifconfig/parse.c:1.15	Tue Apr 20 21:25:25 2010
+++ src/sbin/ifconfig/parse.c	Thu Jul  1 16:44:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.15 2010/04/20 21:25:25 plunky Exp $	*/
+/*	$NetBSD: parse.c,v 1.16 2010/07/01 16:44:05 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: parse.c,v 1.15 2010/04/20 21:25:25 plunky Exp $");
+__RCSID("$NetBSD: parse.c,v 1.16 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -155,7 +155,7 @@
 	}
 
 	len = (int)sizeof(buf);
-	if (get_string(arg, NULL, buf, &len) == NULL) {
+	if (get_string(arg, NULL, buf, &len, ps->ps_hexok) == NULL) {
 		errno = EINVAL;
 		return -1;
 	}

Index: src/sbin/ifconfig/parse.h
diff -u src/sbin/ifconfig/parse.h:1.6 src/sbin/ifconfig/parse.h:1.7
--- src/sbin/ifconfig/parse.h:1.6	Fri Aug  1 22:29:14 2008
+++ src/sbin/ifconfig/parse.h	Thu Jul  1 16:44:05 2010
@@ -83,11 +83,17 @@
 }
 
 #define	PSTR_INITIALIZER(__ps, __name, __defexec, __defkey, __defnext)	\
+    PSTR_INITIALIZER1((__ps), (__name), (__defexec), (__defkey),	\
+    true, (__defnext))
+
+#define	PSTR_INITIALIZER1(__ps, __name, __defexec, __defkey, __defhexok,\
+    __defnext)								\
 {									\
 	.ps_parser = {.p_name = (__name), .p_methods = &pstr_methods,	\
 	               .p_exec = (__defexec),				\
 	               .p_nextparser = (__defnext)},			\
-	.ps_key = (__defkey)						\
+	.ps_key = (__defkey),						\
+	.ps_hexok = (__defhexok)					\
 }
 
 #define	PADDR_INITIALIZER(__pa, __name, __defexec, __addrkey,		\
@@ -203,6 +209,7 @@
 struct pstr {
 	struct parser		ps_parser;
 	const char		*ps_key;
+	bool			ps_hexok;
 };
 
 struct pinteger {
@@ -257,7 +264,7 @@
 struct paddr *paddr_create(const char *, parser_exec_t, const char *,
     const char *, struct parser *);
 struct pstr *pstr_create(const char *, parser_exec_t, const char *,
-    struct parser *);
+    bool, struct parser *);
 struct piface *piface_create(const char *, parser_exec_t, const char *,
     struct parser *);
 struct pkw *pkw_create(const char *, parser_exec_t,

Index: src/sbin/ifconfig/util.c
diff -u src/sbin/ifconfig/util.c:1.14 src/sbin/ifconfig/util.c:1.15
--- src/sbin/ifconfig/util.c:1.14	Thu Jul  1 16:12:23 2010
+++ src/sbin/ifconfig/util.c	Thu Jul  1 16:44:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.14 2010/07/01 16:12:23 dyoung Exp $	*/
+/*	$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2008 David Young.  All rights reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: util.c,v 1.14 2010/07/01 16:12:23 dyoung Exp $");
+__RCSID("$NetBSD: util.c,v 1.15 2010/07/01 16:44:05 dyoung Exp $");
 #endif /* not lint */
 
 #include <ctype.h>
@@ -78,7 +78,8 @@
 }
 
 const char *
-get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp)
+get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp,
+    bool hexok)
 {
 	int len;
 	bool hexstr;
@@ -86,7 +87,7 @@
 
 	len = *lenp;
 	p = buf;
-	hexstr = (val[0] == '0' && tolower((u_char)val[1]) == 'x');
+	hexstr = hexok && val[0] == '0' && tolower((u_char)val[1]) == 'x';
 	if (hexstr)
 		val += 2;
 	for (;;) {

Index: src/sbin/ifconfig/util.h
diff -u src/sbin/ifconfig/util.h:1.8 src/sbin/ifconfig/util.h:1.9
--- src/sbin/ifconfig/util.h:1.8	Fri Sep 11 22:06:29 2009
+++ src/sbin/ifconfig/util.h	Thu Jul  1 16:44:05 2010
@@ -17,7 +17,7 @@
 };
 
 void print_link_addresses(prop_dictionary_t, bool);
-const char *get_string(const char *, const char *, u_int8_t *, int *);
+const char *get_string(const char *, const char *, u_int8_t *, int *, bool);
 const struct afswtch *lookup_af_byname(const char *);
 const struct afswtch *lookup_af_bynum(int);
 void	print_string(const u_int8_t *, int);

Reply via email to