Browse code

Modified sanitize_control_message to remove redacted data from control string rather than blotting it out with "_" chars.

Version 2.1.8

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

James Yonan authored on 2011/07/28 15:01:23
Showing 1 changed files
... ...
@@ -2387,40 +2387,52 @@ openvpn_basename (const char *path)
2387 2387
 }
2388 2388
 
2389 2389
 /*
2390
- * Remove SESS_ID_x strings (i.e. auth tokens) from control message
2391
- * strings so that they will not be output to log file.
2390
+ * Remove security-sensitive strings from control message
2391
+ * so that they will not be output to log file.
2392 2392
  */
2393 2393
 const char *
2394
-sanitize_control_message(const char *str, struct gc_arena *gc)
2394
+sanitize_control_message(const char *src, struct gc_arena *gc)
2395 2395
 {
2396
-  char *ret = gc_malloc (strlen(str)+1, false, gc);
2397
-  char *cp = ret;
2396
+  char *ret = gc_malloc (strlen(src)+1, false, gc);
2397
+  char *dest = ret;
2398 2398
   bool redact = false;
2399
+  int skip = 0;
2399 2400
 
2400
-  strcpy(ret, str);
2401 2401
   for (;;)
2402 2402
     {
2403
-      const char c = *cp;
2403
+      const char c = *src;
2404 2404
       if (c == '\0')
2405 2405
 	  break;
2406
-      if (c == 'S' && !strncmp(cp, "SESS_ID_", 8))
2406
+      if (c == 'S' && !strncmp(src, "SESS_ID_", 8))
2407 2407
 	{
2408
-	  cp += 7;
2408
+	  skip = 7;
2409 2409
 	  redact = true;
2410 2410
 	}
2411
-      else if (c == 'e' && !strncmp(cp, "echo ", 5))
2411
+      else if (c == 'e' && !strncmp(src, "echo ", 5))
2412 2412
 	{
2413
-	  cp += 4;
2413
+	  skip = 4;
2414 2414
 	  redact = true;
2415 2415
 	}
2416
-      else
2416
+
2417
+      if (c == ',') /* end of redacted item? */
2417 2418
 	{
2418
-	  if (c == ',') /* end of session id? */
2419
-	    redact = false;
2420
-	  if (redact)
2421
-	    *cp = '_';
2419
+	  skip = 0;
2420
+	  redact = false;
2422 2421
 	}
2423
-      ++cp;
2422
+
2423
+      if (redact)
2424
+	{
2425
+	  if (skip > 0)
2426
+	    {
2427
+	      --skip;
2428
+	      *dest++ = c;
2429
+	    }
2430
+	}
2431
+      else
2432
+	*dest++ = c;
2433
+
2434
+      ++src;
2424 2435
     }
2436
+  *dest = '\0';
2425 2437
   return ret;
2426 2438
 }