You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/07/16 22:13:22 UTC

git commit: TS-2940: fix varargs corruption when logging fatal errors

Repository: trafficserver
Updated Branches:
  refs/heads/master 4c13e1705 -> 2d653e960


TS-2940: fix varargs corruption when logging fatal errors

When we call the Fatal() macro, make sure to copy the varargs before
logging the error the second time. Also nuke pointless dlfcn wrappers.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/2d653e96
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/2d653e96
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/2d653e96

Branch: refs/heads/master
Commit: 2d653e960679e5e3052a53c1499161f1d977d08f
Parents: 4c13e17
Author: James Peach <jp...@apache.org>
Authored: Fri Jul 11 19:21:32 2014 -0700
Committer: James Peach <jp...@apache.org>
Committed: Wed Jul 16 13:13:05 2014 -0700

----------------------------------------------------------------------
 CHANGES             |  2 ++
 lib/ts/Diags.cc     |  8 +++++++-
 lib/ts/ink_error.cc | 18 ++++++++++--------
 proxy/Plugin.cc     | 42 +++++-------------------------------------
 4 files changed, 24 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d653e96/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index cf0ea95..46a458e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
+  *) [TS-2940] Fix varargs corruption when logging fatal errors.
+
   *) [TS-2935] Clean up semaphore platform code.
 
   *) [TS-2930] missing hostname in ts.client_request.get_url() for lua plugin.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d653e96/lib/ts/Diags.cc
----------------------------------------------------------------------
diff --git a/lib/ts/Diags.cc b/lib/ts/Diags.cc
index ec62648..cb9b3b6 100644
--- a/lib/ts/Diags.cc
+++ b/lib/ts/Diags.cc
@@ -532,6 +532,12 @@ Diags::error_va(DiagsLevel level,
              const char *file, const char *func, const int line,
              const char *format_string, va_list ap) const
 {
+  va_list ap2;
+
+  if (DiagsLevel_IsTerminal(level)) {
+    va_copy(ap2, ap);
+  }
+
   if (show_location) {
     SrcLoc lp(file, func, line);
     print_va(NULL, level, &lp, format_string, ap);
@@ -542,6 +548,6 @@ Diags::error_va(DiagsLevel level,
   if (DiagsLevel_IsTerminal(level)) {
     if (cleanup_func)
       cleanup_func();
-    ink_fatal_va(1, format_string, ap);
+    ink_fatal_va(1, format_string, ap2);
   }
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d653e96/lib/ts/ink_error.cc
----------------------------------------------------------------------
diff --git a/lib/ts/ink_error.cc b/lib/ts/ink_error.cc
index 71122ce..a0b0ad2 100644
--- a/lib/ts/ink_error.cc
+++ b/lib/ts/ink_error.cc
@@ -52,15 +52,17 @@ ink_die_die_die(int retval)
 
 */
 void
-ink_fatal_va(int return_code, const char *message_format, va_list ap)
+ink_fatal_va(int return_code, const char * fmt, va_list ap)
 {
-  char extended_format[4096], message[4096];
-  snprintf(extended_format, sizeof(extended_format) - 1, "FATAL: %s", message_format);
-  extended_format[sizeof(extended_format) - 1] = 0;
-  vsnprintf(message, sizeof(message) - 1, extended_format, ap);
-  message[sizeof(message) - 1] = 0;
-  fprintf(stderr, "%s\n", message);
-  syslog(LOG_CRIT, "%s", message);
+  char msg[1024];
+  const size_t len = sizeof("FATAL: ") - 1;
+
+  strncpy(msg, "FATAL: ", sizeof(msg));
+  vsnprintf(msg + len, sizeof(msg) - len, fmt, ap);
+  msg[sizeof(msg) - 1] = 0;
+
+  fprintf(stderr, "%s\n", msg);
+  syslog(LOG_CRIT, "%s", msg);
   ink_stack_trace_dump();
   ink_die_die_die(return_code);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d653e96/proxy/Plugin.cc
----------------------------------------------------------------------
diff --git a/proxy/Plugin.cc b/proxy/Plugin.cc
index 0a0be5d..ef4c5f8 100644
--- a/proxy/Plugin.cc
+++ b/proxy/Plugin.cc
@@ -22,10 +22,6 @@
  */
 
 #include <stdio.h>
-// XXX: HP-UX ??? Not part of configure supported hosts
-#if defined(hpux)
-#include <dl.h>
-#endif
 #include "ink_platform.h"
 #include "ink_file.h"
 #include "Compatability.h"
@@ -37,16 +33,6 @@
 #include "Plugin.h"
 #include "ink_cap.h"
 
-// HPUX:
-//   LD_SHAREDCMD=ld -b
-// SGI:
-//   LD_SHAREDCMD=ld -shared
-// OSF:
-//   LD_SHAREDCMD=ld -shared -all -expect_unresolved "*"
-// Solaris:
-//   LD_SHAREDCMD=ld -G
-
-
 static const char *plugin_dir = ".";
 
 typedef void (*init_func_t) (int argc, char *argv[]);
@@ -70,24 +56,6 @@ PluginRegInfo::PluginRegInfo()
     plugin_name(NULL), vendor_name(NULL), support_email(NULL)
 { }
 
-static void *
-dll_open(const char *path)
-{
-  return (void *) dlopen(path, RTLD_NOW);
-}
-
-static void *
-dll_findsym(void *dlp, const char *name)
-{
-  return (void *) dlsym(dlp, name);
-}
-
-static char *
-dll_error(void * /* dlp ATS_UNUSED */)
-{
-  return (char *) dlerror();
-}
-
 static void
 plugin_load(int argc, char *argv[])
 {
@@ -118,9 +86,9 @@ plugin_load(int argc, char *argv[])
     REC_ReadConfigInteger(elevate_access, "proxy.config.plugin.load_elevated");
     ElevateAccess access(elevate_access != 0);
 
-    handle = dll_open(path);
+    handle = dlopen(path, RTLD_NOW);
     if (!handle) {
-      Fatal("unable to load '%s': %s", path, dll_error(handle));
+      Fatal("unable to load '%s': %s", path, dlerror());
     }
 
     // Allocate a new registration structure for the
@@ -129,10 +97,10 @@ plugin_load(int argc, char *argv[])
     plugin_reg_current = new PluginRegInfo;
     plugin_reg_current->plugin_path = ats_strdup(path);
 
-    init = (init_func_t) dll_findsym(handle, "TSPluginInit");
+    init = (init_func_t) dlsym(handle, "TSPluginInit");
     if (!init) {
-      Fatal("unable to find TSPluginInit function '%s': %s", path, dll_error(handle));
-      return; // this line won't get called since Fatal brings down ats
+      Fatal("unable to find TSPluginInit function in '%s': %s", path, dlerror());
+      return; // this line won't get called since Fatal brings down ATS
     }
 
     init(argc, argv);