Attached you find an (untested) patch for bug 580039. xdb_file didn't distinguish errors reading a file and files not existing. I think that patch should fix this but I'm not sure the new error mode ("return r_ERR") is handled properly in calling functions.

While the namespace conversion issues are not gone with that patch, there should be proper error messages now which I think is good enough given the fact that probably few people have these problems.
Index: xdb_file/xdb_file.cc
===================================================================
--- xdb_file/xdb_file.cc	(Revision 1566)
+++ xdb_file/xdb_file.cc	(Arbeitskopie)
@@ -111,7 +111,7 @@
  * @param host the host to load the file for (just for generating log messages)
  * @param fname the filename of the file, that should be loaded
  * @param cache a hash containing the cached files, that do not need to get loaded and parsed again
- * @return the loaded (or cached) ::xmlnode
+ * @return the loaded (or cached) ::xmlnode or NULL on error
  */
 xmlnode xdb_file_load(char *host, char *fname, xht cache) {
     xmlnode data = NULL;
@@ -129,24 +129,25 @@
     if (fd < 0) {
 	if (errno == ENOENT) {
 	    log_debug2(ZONE, LOGT_STORAGE, "xdb_file failed to open file %s: %s", fname, strerror(errno));
+	    /* there's nothing on disk, create an empty root node */
+	    data = xmlnode_new_tag_ns("xdb", NULL, NS_JABBERD_XDB);
 	} else {
 	    log_warn(host,"xdb_file failed to open file %s: %s",fname,strerror(errno));
+	    return NULL;
 	}
     } else {
         close(fd);
         data = xmlnode_file(fname);
+        if (data == NULL) {
+	    log_error(host,"xdb_file failed to parse %s - invalid XML?",fname);
+	    return NULL;
+        }
     }
 
-    /* if there's nothing on disk, create an empty root node */
-    if (data == NULL) {
-        data = xmlnode_new_tag_ns("xdb", NULL, NS_JABBERD_XDB);
-    } else {
-	/* did we load an old spool file? update the namespace then */
-	const char *root_element_namespace = xmlnode_get_namespace(data);
-
-	if (root_element_namespace == NULL || j_strcmp(root_element_namespace, NS_SERVER) == 0) {
-	    xmlnode_change_namespace(data, NS_JABBERD_XDB);
-	}
+    /* did we load an old spool file? update the namespace then */
+    const char *root_element_namespace = xmlnode_get_namespace(data);
+    if (root_element_namespace == NULL || j_strcmp(root_element_namespace, NS_SERVER) == 0) {
+	xmlnode_change_namespace(data, NS_JABBERD_XDB);
     }
 
     log_debug2(ZONE, LOGT_STORAGE, "caching %s",fname);
@@ -312,6 +313,10 @@
     /* load the data from disk/cache */
     top = file = xdb_file_load(p->host, full, xf->cache);
 
+    /* error loading file? -> error */
+    if (top == NULL)
+        return r_ERR;
+
     /* if we're dealing w/ a resource, just get that element <res id='resource'/> inside <xdb/> */
     if (p->id->has_resource()) {
 	std::ostringstream xpath;

Reply via email to