Hi List, Willy / Willliam,

A patch i came up with that might make it a little 'safer' with regard to getenv and its return value or possible lack thereof.. I'm not sure it it will ever happen. But if it does it wont fail on a null pointer or empty string conversion to a long value.. Though a arithmetic conversion error could still happen if the value is present but not a number..but well that would be a really odd case.

There are a few things i'm not sure about though.

- What would/could possibly break if mworker_pipe values are left as -1 and the process continues and tries to use it?
- wont the rd wr char* values leak memory?

Anyhow the biggest part that should be noticed of the bug is the sometimes wrongful alert when the fd is actually '0'...

If anything needs to be changed let me know.

Regards,

PiBa-NL / Pieter


From 486d7c759af03f9193ae3e38005d8325ab069b37 Mon Sep 17 00:00:00 2001
From: PiBa-NL <pba_...@yahoo.com>
Date: Tue, 28 Nov 2017 23:22:14 +0100
Subject: [PATCH] [PATCH] BUG/MINOR: Check if master-worker pipe getenv
 succeeded, also allow pipe fd 0 as valid.

On FreeBSD in quiet mode the stdin/stdout/stderr are closed which lets the 
mworker_pipe to use fd 0 and fd 1.
---
 src/haproxy.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/haproxy.c b/src/haproxy.c
index 891a021..c3c8281 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2688,9 +2688,15 @@ int main(int argc, char **argv)
                                        free(msg);
                                }
                        } else {
-                               mworker_pipe[0] = 
atol(getenv("HAPROXY_MWORKER_PIPE_RD"));
-                               mworker_pipe[1] = 
atol(getenv("HAPROXY_MWORKER_PIPE_WR"));
-                               if (mworker_pipe[0] <= 0 || mworker_pipe[1] <= 
0) {
+                               mworker_pipe[0] = -1;
+                               mworker_pipe[1] = -1;
+                               char* rd = getenv("HAPROXY_MWORKER_PIPE_RD");
+                               char* wr = getenv("HAPROXY_MWORKER_PIPE_WR");
+                               if (rd && wr && strlen(rd) > 0 && strlen(wr) > 
0) {
+                                       mworker_pipe[0] = atol(rd);
+                                       mworker_pipe[1] = atol(wr);
+                               }
+                               if (mworker_pipe[0] < 0 || mworker_pipe[1] < 0) 
{
                                        ha_warning("[%s.main()] Cannot get 
master pipe FDs.\n", argv[0]);
                                }
                        }
-- 
2.10.1.windows.1

Reply via email to