fixes infinite loop when trying to overwrite a collection with a regular file

Tue, 12 Dec 2017 23:58:54 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 12 Dec 2017 23:58:54 +0100
changeset 353
e554f3d72d9e
parent 352
76bd29a11cc9
child 354
067ea2315a8a

fixes infinite loop when trying to overwrite a collection with a regular file

dav/main.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Tue Dec 12 23:36:47 2017 +0100
+++ b/dav/main.c	Tue Dec 12 23:58:54 2017 +0100
@@ -1162,6 +1162,15 @@
     } else if(res->iscollection) {
         // TODO: free res
         char *newpath = util_concat_path(path, name);
+        
+        if (!strcmp(path, newpath)) {
+            // TODO: free res
+            fprintf(stderr, "Cannot put file, because a collection with "
+                    "that name already exists.\n");
+            free(newpath);
+            return -1;
+        }
+        
         path = newpath;
         res = dav_resource_new(sn, path);
         free(newpath);

mercurial