add error handling to webdav_xattr_serialze_map()

Sun, 19 Mar 2023 14:02:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Mar 2023 14:02:39 +0100
changeset 483
f69d88f86b9c
parent 482
b02da778362e
child 484
c036a8b242a8

add error handling to webdav_xattr_serialze_map()

src/server/webdav/xattrbackend.c file | annotate | diff | comparison | revisions
--- a/src/server/webdav/xattrbackend.c	Sun Mar 19 11:14:10 2023 +0100
+++ b/src/server/webdav/xattrbackend.c	Sun Mar 19 14:02:39 2023 +0100
@@ -673,17 +673,33 @@
             property_value = &prop->value.data;
         }
         
-        cx_bprintf(&buf, "prop xmlns:%s=\"%s\" %s\n", prop->namespace->prefix, prop->namespace->href, prop->name);
+        int ret = cx_bprintf(&buf, "prop xmlns:%s=\"%s\" %s\n", prop->namespace->prefix, prop->namespace->href, prop->name);
+        if(ret <= 0) {
+            pool_free(pool, buf.space);
+            return (cxmutstr){NULL,0};
+        }
         if(property_value) {
             WebdavNSList *ns = property_value->namespaces; 
             while(ns) {
-                cx_bprintf(&buf, "ns %s:%s\n", prop->namespace->prefix, prop->namespace->href);
+                ret = cx_bprintf(&buf, "ns %s:%s\n", prop->namespace->prefix, prop->namespace->href);
+                if(ret <= 0) {
+                    pool_free(pool, buf.space);
+                    return (cxmutstr){NULL,0};
+                }
                 ns = ns->next;
             }
             
-            cx_bprintf(&buf, "data %zu\n", property_value->length);
+            ret = cx_bprintf(&buf, "data %zu\n", property_value->length);
+            if(ret <= 0) {
+                pool_free(pool, buf.space);
+                return (cxmutstr){NULL,0};
+            }
+            
             cxBufferWrite(property_value->data, 1, property_value->length, &buf);
-            cxBufferPut(&buf, '\n');
+            if(cxBufferPut(&buf, '\n') < 0) {
+                pool_free(pool, buf.space);
+                return (cxmutstr){NULL,0};
+            }
         }
     }
     

mercurial