summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoern Engel <joern@logfs.org>2011-12-18 20:11:25 -0800
committerJoern Engel <joern@logfs.org>2011-12-18 20:11:25 -0800
commitb1ea41673af5b636602cdfb0710dc176dfcc98a8 (patch)
tree0c6331f4643bfc70626e51215c1aa1f7a3d9f73f
parent3d48e466acd97cfa74492de92755d356f4ceba83 (diff)
downloadcancd-b1ea41673af5b636602cdfb0710dc176dfcc98a8.tar.gz
Fix relative path goofup and overflowsv0.1.0
The usage of strncat is a textbook case of when to use strlcat instead. The double strlen is just wasting performance, assuming no buffer overflows in strncat before. And lastly, the program already cd'd into the proper directory. So for a relative path "foo" we created files under "foo/foo/", not under "foo/". Quite a number of bugs to fix by removing so little code. Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r--cancd.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/cancd.c b/cancd.c
index 5ae9d3d..cffc2ee 100644
--- a/cancd.c
+++ b/cancd.c
@@ -163,12 +163,8 @@ static char *get_path(int af, const void *src)
return NULL;
}
- *newstr = '\0';
- strncat(newstr, log_prefix, PATH_MAX);
- strncat(newstr, "/", PATH_MAX);
-
now = time(NULL);
- if (!strftime(newstr + strlen(newstr), PATH_MAX - strlen(newstr), format, localtime(&now))) {
+ if (!strftime(newstr, PATH_MAX, format, localtime(&now))) {
syslog(LOG_ERR, "Unable to format filename: %s", strerror(errno));
free(newstr);
newstr = NULL;