From 5b36bb025a300e39040eac6cf9cf87aae1f4e7a3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 15 Mar 2016 17:49:52 -0400 Subject: multipart-replace-http-server: correctly handle filenames w/o a slash --- multipart-replace-http-server.c | 9 ++++++--- 1 file 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; -- cgit v1.2.3-54-g00ecf