From: Ansis <ansisatt...@gmail.com>

Commit 8a9562 ("dpif-netdev: Add DPDK netdev.") reversed sequence
in which set_program_name() and proctitle_init() functions are
called.  This introduced a regression where program_name and argv_start
would point to exactly the same memory (previously both of these
pointers were pointing to different memory locations because
proctitle_init() would have beforehand created a copy of argv[0]
for the set_program_name() call).

This regression on my system caused ovs-vswitchd monitoring process to
show up without process name:

...  00:00:00 : monitoring pid 26308 (healthy)

Ps output was lacking process name because following code was
using overlapping memory for source and target buffer:.

proctitle_set(const char *format, ...)
{
    ...
    n = snprintf(argv_start, argv_size, "%s: ", program_name);

Overall C99 and POSIX standards state that behavior is undefined
if source and target buffers overlap.

Signed-off-by: Ansis Atteka <aatt...@nicira.com>
---
 lib/util.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/util.c b/lib/util.c
index 01ba6bc..74845dc 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -455,6 +455,10 @@ void
 set_program_name__(const char *argv0, const char *version, const char *date,
                    const char *time)
 {
+    if (program_name) {
+        free(program_name);
+    }
+
 #ifdef _WIN32
     char *basename;
     size_t max_len = strlen(argv0) + 1;
@@ -462,9 +466,6 @@ set_program_name__(const char *argv0, const char *version, 
const char *date,
     SetErrorMode(GetErrorMode() | SEM_NOGPFAULTERRORBOX);
     _set_output_format(_TWO_DIGIT_EXPONENT);
 
-    if (program_name) {
-        free(program_name);
-    }
     basename = xmalloc(max_len);
     _splitpath_s(argv0, NULL, 0, NULL, 0, basename, max_len, NULL, 0);
     assert_single_threaded();
@@ -472,7 +473,7 @@ set_program_name__(const char *argv0, const char *version, 
const char *date,
 #else
     const char *slash = strrchr(argv0, '/');
     assert_single_threaded();
-    program_name = slash ? slash + 1 : argv0;
+    program_name = xstrdup(slash ? slash + 1 : argv0);
 #endif
 
     free(program_version);
-- 
1.8.1.2

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to