Browse code

Fixed bug in proxy fallback capability where openvpn.exe could core dump if http-proxy-fallback-disable command was issued in response to ">PROXY:NEED_NOW management" interface notification.

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@6284 e7ae566f-a301-0410-adde-c780ea21d3b5

James Yonan authored on 2010/07/10 12:04:27
Showing 2 changed files
... ...
@@ -122,7 +122,8 @@ ce_http_proxy_fallback_defined(const struct context *c)
122 122
       int i;
123 123
       for (i = 0; i < l->len; ++i)
124 124
 	{
125
-	  if (l->array[i]->flags & CE_HTTP_PROXY_FALLBACK)
125
+	  const struct connection_entry *ce = l->array[i];
126
+	  if (ce->flags & CE_HTTP_PROXY_FALLBACK)
126 127
 	    return true;
127 128
 	}
128 129
     }
... ...
@@ -193,12 +194,9 @@ management_callback_http_proxy_fallback_cmd (void *arg, const char *server, cons
193 193
 	  struct connection_entry *ce = l->array[i];
194 194
 	  if (ce->flags & CE_HTTP_PROXY_FALLBACK)
195 195
 	    {
196
-	      if (ho)
197
-		{
198
-		  ce->http_proxy_options = ho;
199
-		  ret = true;
200
-		}
196
+	      ce->http_proxy_options = ho;
201 197
 	      ce->ce_http_proxy_fallback_timestamp = now;
198
+	      ret = true;
202 199
 	    }
203 200
 	}
204 201
     }
... ...
@@ -278,7 +276,7 @@ next_connection_entry (struct context *c)
278 278
 
279 279
       do {
280 280
 	const char *remote_ip_hint = NULL;
281
-	bool advanced = false;
281
+	bool newcycle = false;
282 282
 
283 283
 	ce_defined = true;
284 284
 	if (l->no_advance && l->current >= 0)
... ...
@@ -295,7 +293,8 @@ next_connection_entry (struct context *c)
295 295
 		  msg (M_FATAL, "No usable connection profiles are present");
296 296
 	      }
297 297
 
298
-	    advanced = true;
298
+	    if (l->current == 0)
299
+	      newcycle = true;
299 300
 	    show_connection_list(l);
300 301
 	  }
301 302
 
... ...
@@ -305,7 +304,7 @@ next_connection_entry (struct context *c)
305 305
 	  remote_ip_hint = c->options.remote_ip_hint;
306 306
 
307 307
 #if HTTP_PROXY_FALLBACK
308
-	if (advanced && ce_http_proxy_fallback_defined(c))
308
+	if (newcycle && ce_http_proxy_fallback_defined(c))
309 309
 	  ce_http_proxy_fallback_start(c, remote_ip_hint);
310 310
 
311 311
 	if (ce->flags & CE_HTTP_PROXY_FALLBACK)
... ...
@@ -1464,19 +1464,24 @@ parse_http_proxy_fallback (struct context *c,
1464 1464
 			   const char *flags,
1465 1465
 			   const int msglevel)
1466 1466
 {
1467
-  struct gc_arena gc = gc_new ();  
1467
+  struct gc_arena gc = gc_new ();
1468
+  struct http_proxy_options *ret = NULL;
1468 1469
   struct http_proxy_options *hp = parse_http_proxy_override(server, port, flags, msglevel, &gc);
1469
-  struct hpo_store *hpos = c->options.hpo_store;
1470
-  if (!hpos)
1470
+  if (hp)
1471 1471
     {
1472
-      ALLOC_OBJ_CLEAR_GC (hpos, struct hpo_store, &c->options.gc);
1473
-      c->options.hpo_store = hpos;
1472
+      struct hpo_store *hpos = c->options.hpo_store;
1473
+      if (!hpos)
1474
+	{
1475
+	  ALLOC_OBJ_CLEAR_GC (hpos, struct hpo_store, &c->options.gc);
1476
+	  c->options.hpo_store = hpos;
1477
+	}
1478
+      hpos->hpo = *hp;
1479
+      hpos->hpo.server = hpos->server;
1480
+      strncpynt(hpos->server, hp->server, sizeof(hpos->server));
1481
+      ret = &hpos->hpo;
1474 1482
     }
1475
-  hpos->hpo = *hp;
1476
-  hpos->hpo.server = hpos->server;
1477
-  strncpynt(hpos->server, hp->server, sizeof(hpos->server));
1478 1483
   gc_free (&gc);
1479
-  return &hpos->hpo;
1484
+  return ret;
1480 1485
 }
1481 1486
 
1482 1487
 static void