email plugin: Prevent a segfault in read_line ().
[collectd.git] / src / email.c
index 55e0ed5..c1e139e 100644 (file)
 #      include <sys/un.h>
 #endif /* HAVE_LINUX_UN_H | HAVE_SYS_UN_H */
 
+/* some systems (e.g. Darwin) seem to not define UNIX_PATH_MAX at all */
+#ifndef UNIX_PATH_MAX
+# define UNIX_PATH_MAX sizeof (((struct sockaddr_un *)0)->sun_path)
+#endif /* UNIX_PATH_MAX */
+
 #if HAVE_GRP_H
 #      include <grp.h>
 #endif /* HAVE_GRP_H */
@@ -206,7 +211,7 @@ static int email_config (char *key, char *value)
        }
        else if (0 == strcasecmp (key, "SocketPerms")) {
                /* the user is responsible for providing reasonable values */
-               sock_perms = (int)strtol (value, NULL, 0);
+               sock_perms = (int)strtol (value, NULL, 8);
        }
        else if (0 == strcasecmp (key, "MaxConns")) {
                long int tmp = strtol (value, NULL, 0);
@@ -327,7 +332,7 @@ char *read_line (collector_t *src)
                        break;
        }
 
-       if ('\n' != src->buffer[i]) {
+       if (i == src->idx) {
                fd_set fdset;
        
                ssize_t len = 0;
@@ -364,7 +369,7 @@ char *read_line (collector_t *src)
                                break;
                }
 
-               if ('\n' != src->buffer[i]) {
+               if (i == src->idx) {
                        ret = (char *)smalloc (1);
 
                        ret[0] = '\0';