From: <svn...@op...> - 2010-01-25 19:56:11
|
Author: scriptor Date: Mon Jan 25 20:56:01 2010 New Revision: 6022 URL: http://www.opensync.org/changeset/6022 Log: Fixed a bug in the destroy function. Corrected the lines enclosed by the HANDLE_OSYNC_XMLFORMAT define. If multiple entries are to be synchronized, libopensync has difficulties, that in the end can even lead to segmentation faults. In these situations it happens, that the ldap_format plugin gets provided with unexpected types of formats. Enabling HANDLE_OSYNC_XMLFORMAT would allow for the detection of an LDAP related format inside of an OSyncXMLFormat struct. Finally, I have reenabled the HANDLE_OSYNC_XMLFORMAT define. At least for the time being... Modified: plugins/ldap-sync/src/ldap_format.c plugins/ldap-sync/src/ldap_plugin.h Modified: plugins/ldap-sync/src/ldap_format.c ============================================================================== --- plugins/ldap-sync/src/ldap_format.c Sat Jan 23 18:33:22 2010 (r6021) +++ plugins/ldap-sync/src/ldap_format.c Mon Jan 25 20:56:01 2010 (r6022) @@ -148,11 +148,15 @@ ((LDAPMod *)(list->data))->mod_bvalues = NULL; } - g_free(list->data); // this is an LDAPMod... So g_free() maybe insufficient? - list->data = NULL; - } + memset(list->data, 0, sizeof(LDAPMod *)); - } + g_free(list->data); // this is an LDAPMod... So g_free() may be insufficient? + // seg faults, even without that preceding memset(): + // ldap_mods_free((LDAPMod **)&(list->data), 0); + + list->data = NULL; + } // if (list->data) + } // for (list = g_list_first(ldapmods) g_list_free(ldapmods); @@ -633,7 +637,7 @@ gsize n = len > 1024 ? len : 1024; (*destination_entry)->dn = g_strndup(source_entry->dn, n); } else { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: source_entry->dn = NULL. Ignoring.\n", __FILE__, __LINE__); + osync_trace(TRACE_ERROR, "%s:%i: WARNING: source_entry->dn = NULL. Ignoring.\n", __FILE__, __LINE__); (*destination_entry)->dn = NULL; } @@ -6292,6 +6296,22 @@ goto error; } + + // We do not really know, what input exactly is. So any cast is dangerous. + // It SHOULD be a glist_container. Well, who knows... + if (inpsize != sizeof(glist_container)) { + +#ifdef CALL_ABORT + osync_trace(TRACE_ERROR, "%s:%i: ERROR: inpsize = %u. Calling abort()\n", __FILE__, __LINE__, inpsize); + ldap_plugin_printf("%s:%i: ERROR: inpsize = %u. Calling abort()\n", __FILE__, __LINE__, inpsize); + abort(); +#else + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i:%s(): ERROR: inpsize = %i.\n", __FILE__, __LINE__, __func__, inpsize); + goto error; +#endif + } + + if (strncmp(real_input->magic, "glist_container", 15)) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: input was NOT the glist_container that had been expected here in this function.", __FILE__, __LINE__); goto error; @@ -6357,13 +6377,16 @@ } // for (i = 0; i < length; i++) + osync_assert(pre_output != NULL); *output = (char *) pre_output; - *outpsize = sizeof(pre_output); + *outpsize = sizeof(* pre_output); #ifdef DEBUG_destroy_function ldap_plugin_printf("\n%s:%i:%s(): *output = %p\n", __FILE__, __LINE__, __func__, (void *)pre_output); #endif + osync_trace(TRACE_INTERNAL, "%s:%i:%s(): pre_output->magic = \"%s\", pre_output->format_name = \"%s\"", __FILE__, __LINE__, __func__, __NULLSTR(pre_output->magic), __NULLSTR(pre_output->format_name)); + osync_trace(TRACE_INTERNAL, "\n%s:%i:%s(): *output = %p, *outpsize = %u\n", __FILE__, __LINE__, __func__, *output, *outpsize); osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; @@ -6437,9 +6460,10 @@ unsigned int i = 0, j = 0; ldap_entry *entry = NULL; GString *str = NULL; +#ifndef CALL_ABORT xmlChar *xmlbuff = NULL; unsigned int xmlbuff_size = 0; - +#endif osync_trace(TRACE_ENTRY, "%s(%p, %d, %p, %p) ", __func__, (void *)data, size, (void *)user_data, (void *)error); @@ -7698,7 +7722,7 @@ if (container->magic) { if (!strcmp(container->magic, "glist_container")) { - osync_trace(TRACE_INTERNAL, "%s:%i: data looks like a glist_container.", __FILE__, __LINE__); + osync_trace(TRACE_INTERNAL, "%s:%i: Looks like a glist_container.", __FILE__, __LINE__); if (container->format_name == NULL) { osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: container->format_name = NULL.", __FILE__, __LINE__); @@ -7747,14 +7771,14 @@ unsigned int xmlbuff_size = 0; #endif - osync_trace(TRACE_INTERNAL, "%s:%i: data looks like an OSyncXMLFormat. This is most probably NOT an LDAP specific format.", __FILE__, __LINE__); + osync_trace(TRACE_INTERNAL, "%s:%i: Looks like an OSyncXMLFormat. This is probably NOT an LDAP specific format.", __FILE__, __LINE__); #ifdef CALL_ABORT osync_trace(TRACE_ERROR, "%s:%i: Where does that come from? Calling abort().", __FILE__, __LINE__); ldap_plugin_printf("%s:%i: Where does that come from? Calling abort().", __FILE__, __LINE__); - printf(stderr, "%s:%i: Where does that come from? Calling abort().\n\n", __FILE__, __LINE__); + fprintf(stderr, "%s:%i: Where does that come from? Calling abort().\n\n", __FILE__, __LINE__); fflush(stderr); abort(); #endif @@ -7764,8 +7788,10 @@ #ifdef HANDLE_OSYNC_XMLFORMAT osync_assert(data); - if (!osync_xmlformat_assemble((OSyncXMLFormat *)data, &xmlbuff, &xmlbuff_size)) { - osync_trace(TRACE_ERROR, "%s:%i: ERROR: osync_xmlformat_assemble() has failed for an unknown reason. Giving up.\n", __FILE__, __LINE__); + if (!osync_xmlformat_assemble((OSyncXMLFormat *)data, &xmlbuff, &xmlbuff_size, error)) { + if (!osync_error_is_set(error)) + osync_trace(TRACE_ERROR, "%s:%i: ERROR: osync_xmlformat_assemble() has failed for an unknown reason. Giving up.\n", __FILE__, __LINE__); + goto error; } @@ -7790,25 +7816,27 @@ osync_trace(TRACE_INTERNAL, "%s:%i: This is the content of the OSyncXMLFormat:\n\n\n\"%.*s\"\n\n\n", __FILE__, __LINE__, xmlbuff_size, xmlbuff); -#endif - +#else + osync_trace(TRACE_ERROR, "%s:%i:%s(): WARNING: HANDLE_OSYNC_XMLFORMAT has not been defined. So we refuse to detect this kind of format, although we possibly could process it to a certain extent.", __FILE__, __LINE__, __func__); osync_trace(TRACE_EXIT, "%s(): Returning FALSE.", __func__); return FALSE; +#endif + } else if (size == sizeof(ldap_entry)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: data looks like an ldap_entry struct. This is totally wrong. How could that even happen?", __FILE__, __LINE__); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Looks like an ldap_entry struct. This is totally wrong. How could that even happen?", __FILE__, __LINE__); goto error; } else if (size == sizeof(xmlDoc)) { - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: data looks like an xmlDoc.", __FILE__, __LINE__); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Looks like an xmlDoc.", __FILE__, __LINE__); goto error; } else if (size == sizeof(GList)) { unsigned int i = 0; - osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: data looks like a GList.", __FILE__, __LINE__); + osync_error_set(error, OSYNC_ERROR_GENERIC, "%s:%i: ERROR: Looks like a GList.", __FILE__, __LINE__); osync_trace(TRACE_ERROR, "ERROR: data looks like a GList with %u elements.", g_list_length((GList *)data)); @@ -8718,8 +8746,8 @@ */ int dont_free(void) { - ldap_plugin_printf("%s:%i: \n\n\ndont_free() has been called!\n\n", __FILE__, __LINE__); - return 1; + ldap_plugin_printf("%s:%i: \n\n\ndont_free() has been called!\n\n", __FILE__, __LINE__); + return 1; } #endif Modified: plugins/ldap-sync/src/ldap_plugin.h ============================================================================== --- plugins/ldap-sync/src/ldap_plugin.h Sat Jan 23 18:33:22 2010 (r6021) +++ plugins/ldap-sync/src/ldap_plugin.h Mon Jan 25 20:56:01 2010 (r6022) @@ -155,7 +155,7 @@ #define ENABLE_DETECTOR_FUNCTIONS 1 ///< Let the detector functions register ///< and thus take into effect. -// define HANDLE_OSYNC_XMLFORMAT 1 ///< Include some lines about trying to detect +#define HANDLE_OSYNC_XMLFORMAT 1 ///< Include some lines about trying to detect ///< what kind of format is inside an ///< OSyncXMLFormat in ///< ldap_format_do_detect_plain_as_ldap_format(). |