Browse Source

[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 years ago
parent
commit
ed28c8304c
1 changed files with 3 additions and 4 deletions
  1. 3
    4
      src/hci/commands/ifmgmt_cmd.c

+ 3
- 4
src/hci/commands/ifmgmt_cmd.c View File

53
 		    int stop_on_first_success ) {
53
 		    int stop_on_first_success ) {
54
 	struct ifcommon_options opts;
54
 	struct ifcommon_options opts;
55
 	struct net_device *netdev;
55
 	struct net_device *netdev;
56
+	int i;
56
 	int rc;
57
 	int rc;
57
 
58
 
58
 	/* Parse options */
59
 	/* Parse options */
61
 
62
 
62
 	if ( optind != argc ) {
63
 	if ( optind != argc ) {
63
 		/* Treat arguments as a list of interfaces to try */
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
 				continue;
67
 				continue;
68
-			}
69
 			if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
68
 			if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
70
 			     stop_on_first_success ) {
69
 			     stop_on_first_success ) {
71
 				return 0;
70
 				return 0;

Loading…
Cancel
Save