diff --git a/src/common.c b/src/common.c
index db8fce1a99f63b9691595adcfe96a7cc511902d9..43a51a57c5aa7db29ec401852d8919a66404611b 100644 (file)
--- a/src/common.c
+++ b/src/common.c
static int rra_num = 9;
#endif /* HAVE_LIBRRD */
-void
-sstrncpy(char *d, const char *s, int len)
+void sstrncpy (char *d, const char *s, int len)
{
- strncpy(d, s, len);
- d[len - 1] = 0;
+ strncpy (d, s, len);
+ d[len - 1] = '\0';
}
-char *
-sstrdup(const char *s)
+char *sstrdup (const char *s)
{
- char *r = strdup(s);
- if(r == NULL) {
- DBG("Not enough memory.");
+ char *r;
+
+ if((r = strdup (s)) == NULL)
+ {
+ DBG ("Not enough memory.");
exit(3);
}
- return r;
+
+ return (r);
}
-void *
-smalloc(size_t size)
+void *smalloc (size_t size)
{
- void *r = malloc(size);
- if(r == NULL) {
+ void *r;
+
+ if ((r = malloc (size)) == NULL)
+ {
DBG("Not enough memory.");
exit(3);
}
+
return r;
}
+#if 0
+void sfree (void **ptr)
+{
+ if (ptr == NULL)
+ return;
+
+ if (*ptr != NULL)
+ free (*ptr);
+
+ *ptr = NULL;
+}
+#endif
+
int strsplit (char *string, char **fields, size_t size)
{
size_t i;
*/
for (i = 0; i < (fields_num - last_is_file); i++)
{
- /*
- * Join the components together again
- */
- if (strjoin (dir, dir_len, fields, i + 1, "/") < 0)
- return (-1);
-
/*
* Do not create directories that start with a dot. This
* prevents `../../' attacks and other likely malicious
*/
if (fields[i][0] == '.')
{
- syslog (LOG_ERR, "Cowardly refusing to create a directory that begins with a `.' (dot): `%s'", dir);
+ syslog (LOG_ERR, "Cowardly refusing to create a directory that begins with a `.' (dot): `%s'", file_orig);
return (-2);
}
+ /*
+ * Join the components together again
+ */
+ if (strjoin (dir, dir_len, fields, i + 1, "/") < 0)
+ {
+ syslog (LOG_ERR, "strjoin failed: `%s', component #%i", file_orig, i);
+ return (-1);
+ }
+
if (stat (dir, &statbuf) == -1)
{
if (errno == ENOENT)
int i, j;
int status = 0;
+ if (check_create_dir (filename))
+ return (-1);
+
argc = ds_num + rra_num + 4;
if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL)
/* host == NULL => local mode */
if (host != NULL)
{
- if (check_create_dir (host))
- return (-1);
-
if (snprintf (full_file, 1024, "%s/%s", host, file) >= 1024)
return (-1);
}