diff options
author | Joern Engel <joern@logfs.org> | 2011-12-18 20:11:25 -0800 |
---|---|---|
committer | Joern Engel <joern@logfs.org> | 2011-12-18 20:11:25 -0800 |
commit | b1ea41673af5b636602cdfb0710dc176dfcc98a8 (patch) | |
tree | 0c6331f4643bfc70626e51215c1aa1f7a3d9f73f | |
parent | 3d48e466acd97cfa74492de92755d356f4ceba83 (diff) | |
download | cancd-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.c | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -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; |