~ubuntu-branches/ubuntu/lucid/wpasupplicant/lucid-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Description: fix arbitrary command execution via unsanitized string
 passed to action scripts by wpa_cli
Origin: backport, http://w1.fi/security/2014-1/

Index: wpasupplicant-0.6.9/src/utils/os.h
===================================================================
--- wpasupplicant-0.6.9.orig/src/utils/os.h
+++ wpasupplicant-0.6.9/src/utils/os.h
@@ -468,6 +468,15 @@ int os_snprintf(char *str, size_t size,
  */
 size_t os_strlcpy(char *dest, const char *src, size_t siz);
 
+/**
+ * os_exec - Execute an external program
+ * @program: Path to the program
+ * @arg: Command line argument string
+ * @wait_completion: Whether to wait until the program execution completes
+ * Returns: 0 on success, -1 on error
+ */
+int os_exec(const char *program, const char *arg, int wait_completion);
+
 
 #ifdef OS_REJECT_C_LIB_FUNCTIONS
 #define malloc OS_DO_NOT_USE_malloc
Index: wpasupplicant-0.6.9/src/utils/os_unix.c
===================================================================
--- wpasupplicant-0.6.9.orig/src/utils/os_unix.c
+++ wpasupplicant-0.6.9/src/utils/os_unix.c
@@ -14,6 +14,8 @@
 
 #include "includes.h"
 
+#include <sys/wait.h>
+
 #include "os.h"
 
 void os_sleep(os_time_t sec, os_time_t usec)
@@ -296,3 +298,57 @@ size_t os_strlcpy(char *dest, const char
 
 	return s - src - 1;
 }
+
+
+int os_exec(const char *program, const char *arg, int wait_completion)
+{
+	pid_t pid;
+	int pid_status;
+
+	pid = fork();
+	if (pid < 0) {
+		perror("fork");
+		return -1;
+	}
+
+	if (pid == 0) {
+		/* run the external command in the child process */
+		const int MAX_ARG = 30;
+		char *_program, *_arg, *pos;
+		char *argv[MAX_ARG + 1];
+		int i;
+
+		_program = os_strdup(program);
+		_arg = os_strdup(arg);
+
+		argv[0] = _program;
+
+		i = 1;
+		pos = _arg;
+		while (i < MAX_ARG && pos && *pos) {
+			while (*pos == ' ')
+				pos++;
+			if (*pos == '\0')
+				break;
+			argv[i++] = pos;
+			pos = os_strchr(pos, ' ');
+			if (pos)
+				*pos++ = '\0';
+		}
+		argv[i] = NULL;
+
+		execv(program, argv);
+		perror("execv");
+		os_free(_program);
+		os_free(_arg);
+		exit(0);
+		return -1;
+	}
+
+	if (wait_completion) {
+		/* wait for the child process to complete in the parent */
+		waitpid(pid, &pid_status, 0);
+	}
+
+	return 0;
+}
Index: wpasupplicant-0.6.9/src/utils/os_win32.c
===================================================================
--- wpasupplicant-0.6.9.orig/src/utils/os_win32.c
+++ wpasupplicant-0.6.9/src/utils/os_win32.c
@@ -220,3 +220,9 @@ size_t os_strlcpy(char *dest, const char
 
 	return s - src - 1;
 }
+
+
+int os_exec(const char *program, const char *arg, int wait_completion)
+{
+	return -1;
+}
Index: wpasupplicant-0.6.9/wpa_supplicant/wpa_cli.c
===================================================================
--- wpasupplicant-0.6.9.orig/wpa_supplicant/wpa_cli.c
+++ wpasupplicant-0.6.9/wpa_supplicant/wpa_cli.c
@@ -1349,28 +1349,19 @@ static int str_match(const char *a, cons
 static int wpa_cli_exec(const char *program, const char *arg1,
 			const char *arg2)
 {
-	char *cmd;
+	char *arg;
 	size_t len;
 	int res;
-	int ret = 0;
 
-	len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
-	cmd = os_malloc(len);
-	if (cmd == NULL)
+	len = os_strlen(arg1) + os_strlen(arg2) + 2;
+	arg = os_malloc(len);
+	if (arg == NULL)
 		return -1;
-	res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
-	if (res < 0 || (size_t) res >= len) {
-		os_free(cmd);
-		return -1;
-	}
-	cmd[len - 1] = '\0';
-#ifndef _WIN32_WCE
-	if (system(cmd) < 0)
-		ret = -1;
-#endif /* _WIN32_WCE */
-	os_free(cmd);
+	os_snprintf(arg, len, "%s %s", arg1, arg2);
+	res = os_exec(program, arg, 1);
+	os_free(arg);
 
-	return ret;
+	return res;
 }