-- 
Martin
--- Begin Message ---
I have an update for my patch that you can put in place of the current one.  
This time it doesn't have a blatant buffer overflow ;)

Thanks,

-Charles
--- hosts.c.orig	Sun Oct  6 19:51:21 2002
+++ hosts.c	Mon Nov 18 15:29:32 2002
@@ -72,6 +72,9 @@
 #include <errno.h>
 #include <time.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "distcc.h"
 #include "trace.h"
@@ -117,9 +120,47 @@
     char *where;
 
     where = getenv("DISTCC_HOSTS");
-    if (!where) {
-        rs_log_warning("$DISTCC_HOSTS is not defined; can't distribute work");
-        return EXIT_BAD_HOSTSPEC;
+	if (!where) {
+        char *filename;
+        int file;
+        char buffer[4096];
+        int readcount;
+        char *listbuf=0;
+        int listbufsize=4096;
+        int listbuflen=0;
+        int parseresult;
+        
+        listbuf = malloc(4096);
+        
+        filename = getenv("DISTCC_HOSTS_FILE");
+        if (!filename)
+        {
+            rs_log_warning("$DISTCC_HOSTS or $DISTCC_HOSTS_FILE not defined;"
+                           " can't distribute work");
+            return 1;
+        }
+        file = open(filename, O_RDONLY);
+
+        while ((readcount = read(file, buffer, 4096)) > 0)
+        {
+            if (readcount+listbuflen > listbufsize)
+            {
+                char *temp;
+                temp = malloc(readcount+listbuflen);
+                memcpy(temp, listbuf, listbuflen);
+                free(listbuf);
+                listbuf = temp;
+                listbufsize = readcount+listbuflen;
+            }
+            memcpy(listbuf+listbuflen, buffer, readcount);
+			listbuflen += readcount;
+        }
+        listbuf[listbuflen] = 0;
+        close(file);
+        /* ok, I've read the file, now have it parsed */
+        parseresult = dcc_parse_hosts(listbuf, ret_list, ret_nhosts);
+        free(listbuf);
+        return parseresult;
     }
 
     return dcc_parse_hosts(where, ret_list, ret_nhosts);
@@ -306,7 +347,7 @@
     if (*ret_nhosts) {
         return 0;
     } else {
-        rs_log_warning("$DISTCC_HOSTS is empty; can't distribute work"); 
+        rs_log_warning("$DISTCC_HOSTS or $DISTCC_HOSTS_FILE is empty; can't distribute work"); 
         return EXIT_BAD_HOSTSPEC;
     }
 }
--- End Message ---

Reply via email to