--- a/src/fwalls/hosts.c	2012-04-20 15:25:23.000000000 -0700
+++ b/src/fwalls/hosts.c	2012-04-20 15:25:36.000000000 -0700
@@ -19,6 +19,7 @@
  */
 
 #include <stdio.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -66,7 +67,21 @@
 }
 
 static FILE *make_temporary_conffile(void) {
-    return  fopen(tempflname, "a+");
+    FILE *f;
+
+    f = fopen(tempflname, "w+");
+    if (f == NULL) return NULL;
+
+    /* make sure to secure file permissions (-rw-r--r--) */
+    if (chmod(tempflname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) {
+        /* could not secure perms, return full failure */
+        sshguard_log(LOG_ERR, "Error in chmod(): %s", strerror(errno));
+        fclose(f);
+        unlink(tempflname);
+        return NULL;
+    }
+
+    return f;
 }
 
 static int install_temporary_conffile() {
