summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-03-15 17:49:52 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-03-15 17:49:52 -0400
commit5b36bb025a300e39040eac6cf9cf87aae1f4e7a3 (patch)
tree352fa628b3aa09d02c6c4b0df3fbbad3e3a5055a
parent1d3ea2976f0c71d95c4bb400d90f6bd84c31be1a (diff)
multipart-replace-http-server: correctly handle filenames w/o a slash
-rw-r--r--multipart-replace-http-server.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/multipart-replace-http-server.c b/multipart-replace-http-server.c
index a5b1c8b..a6a7870 100644
--- a/multipart-replace-http-server.c
+++ b/multipart-replace-http-server.c
@@ -53,9 +53,12 @@ void file_add(const char *filename) {
if (fd < 0)
error(EXIT_FAILURE, errno, "opening file: %s", filename);
filev = xrealloc(filev, (++filec)*sizeof(*filev));
- const char *shortname = strrchr(filename, '/');
- if (shortname == NULL)
- shortname = filename;
+ char *shortname = strrchr(filename, '/');
+ if (shortname == NULL) {
+ shortname = alloca(strlen(filename)+2);
+ shortname[0] = '/';
+ strcpy(&shortname[1], filename);
+ }
strncpy(filev[filec-1].name, shortname, sizeof(filev[filec-1].name));
error(0, 0, "added file #%zd: %s", filec-1, filev[filec-1].name);
filev[filec-1].stream = stream;