Skip to content
Snippets Groups Projects
  1. Aug 17, 2012
    • Tom Lane's avatar
      Check LIBXML_VERSION instead of testing in configure script. · 33f40976
      Tom Lane authored
      We had put a test for libxml2's xmlStructuredErrorContext variable in
      configure, but of course that doesn't work on Windows builds.  The next
      best alternative seems to be to test the LIBXML_VERSION symbol provided
      by xmlversion.h.
      
      Per report from Talha Bin Rizwan, though this fixes it in a different way
      than his proposed patch.
      33f40976
  2. Aug 15, 2012
    • Tom Lane's avatar
      Prevent access to external files/URLs via XML entity references. · aa2bc1f2
      Tom Lane authored
      xml_parse() would attempt to fetch external files or URLs as needed to
      resolve DTD and entity references in an XML value, thus allowing
      unprivileged database users to attempt to fetch data with the privileges
      of the database server.  While the external data wouldn't get returned
      directly to the user, portions of it could be exposed in error messages
      if the data didn't parse as valid XML; and in any case the mere ability
      to check existence of a file might be useful to an attacker.
      
      The ideal solution to this would still allow fetching of references that
      are listed in the host system's XML catalogs, so that documents can be
      validated according to installed DTDs.  However, doing that with the
      available libxml2 APIs appears complex and error-prone, so we're not going
      to risk it in a security patch that necessarily hasn't gotten wide review.
      So this patch merely shuts off all access, causing any external fetch to
      silently expand to an empty string.  A future patch may improve this.
      
      In HEAD and 9.2, also suppress warnings about undefined entities, which
      would otherwise occur as a result of not loading referenced DTDs.  Previous
      branches don't show such warnings anyway, due to different error handling
      arrangements.
      
      Credit to Noah Misch for first reporting the problem, and for much work
      towards a solution, though this simplistic approach was not his preference.
      Also thanks to Daniel Veillard for consultation.
      
      Security: CVE-2012-3489
      aa2bc1f2
  3. Jun 10, 2012
  4. Mar 15, 2012
  5. Mar 14, 2012
  6. Feb 28, 2012
  7. Jan 02, 2012
  8. Sep 11, 2011
    • Peter Eisentraut's avatar
      Remove many -Wcast-qual warnings · 1b81c2fe
      Peter Eisentraut authored
      This addresses only those cases that are easy to fix by adding or
      moving a const qualifier or removing an unnecessary cast.  There are
      many more complicated cases remaining.
      1b81c2fe
  9. Jul 26, 2011
  10. Jul 21, 2011
    • Tom Lane's avatar
      Make xpath() do something useful with XPath expressions that return scalars. · 0ce7676a
      Tom Lane authored
      Previously, xpath() simply returned an empty array if the expression did
      not yield a node set.  This is useless for expressions that return scalars,
      such as one with name() at the top level.  Arrange to return the scalar
      value as a single-element xml array, instead.  (String values will be
      suitably escaped.)
      
      This change will also cause xpath_exists() to return true, not false,
      for such expressions.
      
      Florian Pflug, reviewed by Radoslaw Smogura
      0ce7676a
    • Tom Lane's avatar
      Ensure that xpath() escapes special characters in string values. · aaf15e5c
      Tom Lane authored
      Without this it's possible for the output to not be legal XML, as
      illustrated by the added regression test cases.
      
      NB: this change will need to be called out as an incompatibility in the
      9.2 release notes, since it's possible somebody was relying on the old
      behavior, even though it's clearly wrong.
      
      Florian Pflug, reviewed by Radoslaw Smogura
      aaf15e5c
  11. Jul 20, 2011
    • Tom Lane's avatar
      Rewrite libxml error handling to be more robust. · cacd42d6
      Tom Lane authored
      libxml reports some errors (like invalid xmlns attributes) via the error
      handler hook, but still returns a success indicator to the library caller.
      This causes us to miss some errors that are important to report.  Since the
      "generic" error handler hook doesn't know whether the message it's getting
      is for an error, warning, or notice, stop using that and instead start
      using the "structured" error handler hook, which gets enough information
      to be useful.
      
      While at it, arrange to save and restore the error handler hook setting in
      each libxml-using function, rather than assuming we can set and forget the
      hook.  This should improve the odds of working nicely with third-party
      libraries that also use libxml.
      
      In passing, volatile-ize some local variables that get modified within
      PG_TRY blocks.  I noticed this while testing with an older gcc version
      than I'd previously tried to compile xml.c with.
      
      Florian Pflug and Tom Lane, with extensive review/testing by Noah Misch
      cacd42d6
  12. Jul 16, 2011
  13. Jul 04, 2011
  14. May 28, 2011
    • Tom Lane's avatar
      Fix null-dereference crash in parse_xml_decl(). · 5e1365a9
      Tom Lane authored
      parse_xml_decl's header comment says you can pass NULL for any unwanted
      output parameter, but it failed to honor this contract for the "standalone"
      flag.  The only currently-affected caller is xml_recv, so the net effect is
      that sending a binary XML value containing a standalone parameter in its
      xml declaration would crash the backend.  Per bug #6044 from Christopher
      Dillard.
      
      In passing, remove useless initializations of parse_xml_decl's output
      parameters in xml_parse.
      
      Back-patch to 8.3, where this code was introduced.
      5e1365a9
  15. Apr 10, 2011
  16. Jan 01, 2011
  17. Nov 23, 2010
  18. Oct 21, 2010
    • Tom Lane's avatar
      Improve handling of domains over arrays. · 529cb267
      Tom Lane authored
      This patch eliminates various bizarre behaviors caused by sloppy thinking
      about the difference between a domain type and its underlying array type.
      In particular, the operation of updating one element of such an array
      has to be considered as yielding a value of the underlying array type,
      *not* a value of the domain, because there's no assurance that the
      domain's CHECK constraints are still satisfied.  If we're intending to
      store the result back into a domain column, we have to re-cast to the
      domain type so that constraints are re-checked.
      
      For similar reasons, such a domain can't be blindly matched to an ANYARRAY
      polymorphic parameter, because the polymorphic function is likely to apply
      array-ish operations that could invalidate the domain constraints.  For the
      moment, we just forbid such matching.  We might later wish to insert an
      automatic downcast to the underlying array type, but such a change should
      also change matching of domains to ANYELEMENT for consistency.
      
      To ensure that all such logic is rechecked, this patch removes the original
      hack of setting a domain's pg_type.typelem field to match its base type;
      the typelem will always be zero instead.  In those places where it's really
      okay to look through the domain type with no other logic changes, use the
      newly added get_base_element_type function in place of get_element_type.
      catversion bumped due to change in pg_type contents.
      
      Per bug #5717 from Richard Huxton and subsequent discussion.
      529cb267
  19. Oct 15, 2010
  20. Sep 20, 2010
  21. Aug 13, 2010
  22. Aug 08, 2010
  23. Aug 05, 2010
  24. Jul 06, 2010
  25. Mar 03, 2010
    • Tom Lane's avatar
      Export xml.c's libxml-error-handling support so that contrib/xml2 can use it · 8bf14182
      Tom Lane authored
      too, instead of duplicating the functionality (badly).
      
      I renamed xml_init to pg_xml_init, because the former seemed just a bit too
      generic to be safe as a global symbol.  I considered likewise renaming
      xml_ereport to pg_xml_ereport, but felt that the reference to ereport probably
      made it sufficiently PG-centric already.
      8bf14182
  26. Feb 14, 2010
    • Robert Haas's avatar
      Wrap calls to SearchSysCache and related functions using macros. · e26c539e
      Robert Haas authored
      The purpose of this change is to eliminate the need for every caller
      of SearchSysCache, SearchSysCacheCopy, SearchSysCacheExists,
      GetSysCacheOid, and SearchSysCacheList to know the maximum number
      of allowable keys for a syscache entry (currently 4).  This will
      make it far easier to increase the maximum number of keys in a
      future release should we choose to do so, and it makes the code
      shorter, too.
      
      Design and review by Tom Lane.
      e26c539e
  27. Jan 02, 2010
  28. Sep 04, 2009
  29. Aug 10, 2009
  30. Jun 11, 2009
  31. Jun 10, 2009
  32. Jun 08, 2009
  33. May 13, 2009
    • Tom Lane's avatar
      Rewrite xml.c's memory management (yet again). Give up on the idea of · 23543c73
      Tom Lane authored
      redirecting libxml's allocations into a Postgres context.  Instead, just let
      it use malloc directly, and add PG_TRY blocks as needed to be sure we release
      libxml data structures in error recovery code paths.  This is ugly but seems
      much more likely to play nicely with third-party uses of libxml, as seen in
      recent trouble reports about using Perl XML facilities in pl/perl and bug
      #4774 about contrib/xml2.
      
      I left the code for allocation redirection in place, but it's only
      built/used if you #define USE_LIBXMLCONTEXT.  This is because I found it
      useful to corral libxml's allocations in a palloc context when hunting
      for libxml memory leaks, and we're surely going to have more of those
      in the future with this type of approach.  But we don't want it turned on
      in a normal build because it breaks exactly what we need to fix.
      
      I have not re-indented most of the code sections that are now wrapped
      by PG_TRY(); that's for ease of review.  pg_indent will fix it.
      
      This is a pre-existing bug in 8.3, but I don't dare back-patch this change
      until it's gotten a reasonable amount of field testing.
      23543c73
  34. May 12, 2009
    • Tom Lane's avatar
      Fix intratransaction memory leaks in xml_recv, xmlconcat, xmlroot, and · 546454f8
      Tom Lane authored
      xml_parse, all arising from the same sloppy usage of parse_xml_decl.
      The original coding had that function returning its output string
      parameters in the libxml context, which is long-lived, and all but one
      of its callers neglected to free the strings afterwards.  The easiest
      and most bulletproof fix is to return the strings in the local palloc
      context instead, since that's short-lived.  This was only costing a
      dozen or two bytes per function call, but that adds up fast if the
      function is called repeatedly ...
      
      Noted while poking at the more general problem of what to do with our
      libxml memory allocation hooks.  Back-patch to 8.3, which has the
      identical coding.
      546454f8
  35. Apr 08, 2009
  36. Mar 27, 2009
  37. Mar 23, 2009
  38. Jan 07, 2009
Loading