ソースを参照

[ifmgmt] Avoid relying on global variable within ifcommon_exec()

The getopt API defines optind as a global variable.  When used by the
"autoboot" command, the payload function passed to ifcommon_exec() may
result in a new iPXE script being executed; the commands therein would
then overwrite the value of optind.  On returning, ifcommon_exec()
would continue processing the list of interfaces from an undefined
point.

Fix by using a local variable to hold the index within the list of
interfaces.

Reported-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11年前
コミット
ed28c8304c
1個のファイルの変更3行の追加4行の削除
  1. 3
    4
      src/hci/commands/ifmgmt_cmd.c

+ 3
- 4
src/hci/commands/ifmgmt_cmd.c ファイルの表示

@@ -53,6 +53,7 @@ int ifcommon_exec ( int argc, char **argv,
53 53
 		    int stop_on_first_success ) {
54 54
 	struct ifcommon_options opts;
55 55
 	struct net_device *netdev;
56
+	int i;
56 57
 	int rc;
57 58
 
58 59
 	/* Parse options */
@@ -61,11 +62,9 @@ int ifcommon_exec ( int argc, char **argv,
61 62
 
62 63
 	if ( optind != argc ) {
63 64
 		/* Treat arguments as a list of interfaces to try */
64
-		while ( optind != argc ) {
65
-			if ( ( rc = parse_netdev ( argv[optind++],
66
-						   &netdev ) ) != 0 ) {
65
+		for ( i = optind ; i < argc ; i++ ) {
66
+			if ( ( rc = parse_netdev ( argv[i], &netdev ) ) != 0 )
67 67
 				continue;
68
-			}
69 68
 			if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
70 69
 			     stop_on_first_success ) {
71 70
 				return 0;

読み込み中…
キャンセル
保存