Question

I have some code that is very similar to the example at http://www.aleksey.com/xmlsec/api/xmlsec-examples-sign-template-file.html:

#ifndef XMLSEC_NO_XSLT
    xsltSecurityPrefsPtr xsltSecPrefs = NULL;
#endif /* XMLSEC_NO_XSLT */

    /* Init libxml and libxslt libraries */
    xmlInitParser();
    LIBXML_TEST_VERSION
    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
    xmlSubstituteEntitiesDefault(1);

    /* Init libxslt */
#ifndef XMLSEC_NO_XSLT
    /* disable everything */
    xsltSecPrefs = xsltNewSecurityPrefs(); 
    xsltSetSecurityPrefs(xsltSecPrefs,  XSLT_SECPREF_READ_FILE,        xsltSecurityForbid);
    xsltSetSecurityPrefs(xsltSecPrefs,  XSLT_SECPREF_WRITE_FILE,       xsltSecurityForbid);
    xsltSetSecurityPrefs(xsltSecPrefs,  XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
    xsltSetSecurityPrefs(xsltSecPrefs,  XSLT_SECPREF_READ_NETWORK,     xsltSecurityForbid);
    xsltSetSecurityPrefs(xsltSecPrefs,  XSLT_SECPREF_WRITE_NETWORK,    xsltSecurityForbid);
    xsltSetDefaultSecurityPrefs(xsltSecPrefs); 
#endif /* XMLSEC_NO_XSLT */                

    /* Init xmlsec library */
    if(xmlSecInit() < 0) {
        fprintf(stderr, "Error: xmlsec initialization failed.\n");
        return(-1);
    }

The problem is that while xmlSecInit succeeds (returns 0), it logs this assertion failure to stderr:

func=xmlSecTransformXsltInitialize:file=xslt.c:line=109:obj=unknown:subj=g_xslt_default_security_prefs == NULL:error=100:assertion:

I suspect it's harmless, but there's probably a reason the error is being logged. I want to know how to avoid it.

I do not have XMLSEC_NO_XSLT defined, so those lines of codes in the #ifdefs do execute.

Thanks!

Was it helpful?

Solution

I looked at the xmlsec source, and it looks like xmlSecInit calls xmlSecTransformIdsInit, which calls xmlSecTransformXsltInitialize. The first thing that last function does is check that g_xslt_default_security_prefs is NULL. Then, it sets g_xslt_default_security_prefs.

Long story short, I was calling xmlSecInit() more than once, and should not do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top