浏览代码

[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
 		    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;

正在加载...
取消
保存