Skip to content
Snippets Groups Projects
  1. Jun 19, 2016
    • Tom Lane's avatar
      Docs: improve description of psql's %R prompt escape sequence. · 09e592b3
      Tom Lane authored
      Dilian Palauzov pointed out in bug #14201 that the docs failed to mention
      the possibility of %R producing '(' due to an unmatched parenthesis.
      
      He proposed just adding that in the same style as the other options were
      listed; but it seemed to me that the sentence was already nearly
      unintelligible, so I rewrote it a bit more extensively.
      
      Report: <20160619121113.5789.68274@wrigleys.postgresql.org>
      09e592b3
  2. Jun 16, 2016
    • Tom Lane's avatar
      Fix validation of overly-long IPv6 addresses. · f66e0fec
      Tom Lane authored
      The inet/cidr types sometimes failed to reject IPv6 inputs with too many
      colon-separated fields, instead translating them to '::/0'.  This is the
      result of a thinko in the original ISC code that seems to be as yet
      unreported elsewhere.  Per bug #14198 from Stefan Kaltenbrunner.
      
      Report: <20160616182222.5798.959@wrigleys.postgresql.org>
      f66e0fec
    • Tom Lane's avatar
      Avoid crash in "postgres -C guc" for a GUC with a null string value. · 23ed284a
      Tom Lane authored
      Emit "(null)" instead, which was the behavior all along on platforms
      that don't crash, eg OS X.  Per report from Jehan-Guillaume de Rorthais.
      Back-patch to 9.2 where -C option was introduced.
      
      Michael Paquier
      
      Report: <20160615204036.2d35d86a@firost>
      23ed284a
  3. Jun 13, 2016
    • Tom Lane's avatar
      Fix multiple minor infelicities in aclchk.c error reports. · cd05539e
      Tom Lane authored
      pg_type_aclmask reported the wrong type's OID when complaining that
      it could not find a type's typelem.  It also failed to provide a
      suitable errcode when the initially given OID doesn't exist (which
      is a user-facing error, since that OID can be user-specified).
      pg_foreign_data_wrapper_aclmask and pg_foreign_server_aclmask likewise
      lacked errcode specifications.  Trivial cosmetic adjustments too.
      
      The wrong-type-OID problem was reported by Petru-Florin Mihancea in
      bug #14186; the other issues noted by me while reading the code.
      These errors all seem to be aboriginal in the respective routines, so
      back-patch as necessary.
      
      Report: <20160613163159.5798.52928@wrigleys.postgresql.org>
      cd05539e
  4. Jun 09, 2016
    • Tom Lane's avatar
      Clarify documentation of ceil/ceiling/floor functions. · a36c8219
      Tom Lane authored
      Document these as "nearest integer >= argument" and "nearest integer <=
      argument", which will hopefully be less confusing than the old formulation.
      New wording is from Matlab via Dean Rasheed.
      
      I changed the pg_description entries as well as the SGML docs.  In the
      back branches, this will only affect installations initdb'd in the future,
      but it should be harmless otherwise.
      
      Discussion: <CAEZATCW3yzJo-NMSiQs5jXNFbTsCEftZS-Og8=FvFdiU+kYuSA@mail.gmail.com>
      a36c8219
  5. Jun 08, 2016
    • Alvaro Herrera's avatar
      nls-global.mk: search build dir for source files, too · 3dcdf980
      Alvaro Herrera authored
      In VPATH builds, the build directory was not being searched for files in
      GETTEXT_FILES, leading to failure to construct the .pot files.  This has
      bit me all along, but never hard enough to get it fixed; I suppose not a
      lot of people uses VPATH and NLS-enabled builds, and those that do,
      don't do "make update-po" often.
      
      This is a longstanding problem, so backpatch all the way back.
      3dcdf980
  6. Jun 06, 2016
    • Tom Lane's avatar
      Don't reset changes_since_analyze after a selective-columns ANALYZE. · 3201709d
      Tom Lane authored
      If we ANALYZE only selected columns of a table, we should not postpone
      auto-analyze because of that; other columns may well still need stats
      updates.  As committed, the counter is left alone if a column list is
      given, whether or not it includes all analyzable columns of the table.
      Per complaint from Tomasz Ostrowski.
      
      It's been like this a long time, so back-patch to all supported branches.
      
      Report: <ef99c1bd-ff60-5f32-2733-c7b504eb960c@ato.waw.pl>
      3201709d
  7. May 26, 2016
    • Alvaro Herrera's avatar
      Avoid hot standby cancels from VAC FREEZE · 294509ea
      Alvaro Herrera authored
      VACUUM FREEZE generated false cancelations of standby queries on an
      otherwise idle master. Caused by an off-by-one error on cutoff_xid
      which goes back to original commit.
      
      Analysis and report by Marco Nenciarini
      
      Bug fix by Simon Riggs
      
      This is a correct backpatch of commit 66fbcb0d to branches 9.1 through
      9.4.  That commit was backpatched to 9.0 originally, but it was
      immediately reverted in 9.0-9.4 because it didn't compile.
      294509ea
  8. May 24, 2016
    • Tom Lane's avatar
      Fetch XIDs atomically during vac_truncate_clog(). · 4cf0978e
      Tom Lane authored
      Because vac_update_datfrozenxid() updates datfrozenxid and datminmxid
      in-place, it's unsafe to assume that successive reads of those values will
      give consistent results.  Fetch each one just once to ensure sane behavior
      in the minimum calculation.  Noted while reviewing Alexander Korotkov's
      patch in the same area.
      
      Discussion: <8564.1464116473@sss.pgh.pa.us>
      4cf0978e
    • Tom Lane's avatar
      Avoid consuming an XID during vac_truncate_clog(). · 2e7f0c34
      Tom Lane authored
      vac_truncate_clog() uses its own transaction ID as the comparison point in
      a sanity check that no database's datfrozenxid has already wrapped around
      "into the future".  That was probably fine when written, but in a lazy
      vacuum we won't have assigned an XID, so calling GetCurrentTransactionId()
      causes an XID to be assigned when otherwise one would not be.  Most of the
      time that's not a big problem ... but if we are hard up against the
      wraparound limit, consuming XIDs during antiwraparound vacuums is a very
      bad thing.
      
      Instead, use ReadNewTransactionId(), which not only avoids this problem
      but is in itself a better comparison point to test whether wraparound
      has already occurred.
      
      Report and patch by Alexander Korotkov.  Back-patch to all versions.
      
      Report: <CAPpHfdspOkmiQsxh-UZw2chM6dRMwXAJGEmmbmqYR=yvM7-s6A@mail.gmail.com>
      2e7f0c34
  9. May 23, 2016
    • Tom Lane's avatar
      Fix latent crash in do_text_output_multiline(). · fca2eb3d
      Tom Lane authored
      do_text_output_multiline() would fail (typically with a null pointer
      dereference crash) if its input string did not end with a newline.  Such
      cases do not arise in our current sources; but it certainly could happen
      in future, or in extension code's usage of the function, so we should fix
      it.  To fix, replace "eol += len" with "eol = text + len".
      
      While at it, make two cosmetic improvements: mark the input string const,
      and rename the argument from "text" to "txt" to dodge pgindent strangeness
      (since "text" is a typedef name).
      
      Even though this problem is only latent at present, it seems like a good
      idea to back-patch the fix, since it's a very simple/safe patch and it's
      not out of the realm of possibility that we might in future back-patch
      something that expects sane behavior from do_text_output_multiline().
      
      Per report from Hao Lee.
      
      Report: <CAGoxFiFPAGyPAJLcFxTB5cGhTW2yOVBDYeqDugYwV4dEd1L_Ag@mail.gmail.com>
      fca2eb3d
  10. May 20, 2016
  11. May 14, 2016
  12. May 13, 2016
    • Tom Lane's avatar
      Ensure plan stability in contrib/btree_gist regression test. · b15ab18e
      Tom Lane authored
      Buildfarm member skink failed with symptoms suggesting that an
      auto-analyze had happened and changed the plan displayed for a
      test query.  Although this is evidently of low probability,
      regression tests that sometimes fail are no fun, so add commands
      to force a bitmap scan to be chosen.
      b15ab18e
  13. May 10, 2016
  14. May 09, 2016
  15. May 07, 2016
    • Tom Lane's avatar
      fded7669
    • Peter Eisentraut's avatar
      Distrust external OpenSSL clients; clear err queue · e3a493ac
      Peter Eisentraut authored
      OpenSSL has an unfortunate tendency to mix per-session state error
      handling with per-thread error handling.  This can cause problems when
      programs that link to libpq with OpenSSL enabled have some other use of
      OpenSSL; without care, one caller of OpenSSL may cause problems for the
      other caller.  Backend code might similarly be affected, for example
      when a third party extension independently uses OpenSSL without taking
      the appropriate precautions.
      
      To fix, don't trust other users of OpenSSL to clear the per-thread error
      queue.  Instead, clear the entire per-thread queue ahead of certain I/O
      operations when it appears that there might be trouble (these I/O
      operations mostly need to call SSL_get_error() to check for success,
      which relies on the queue being empty).  This is slightly aggressive,
      but it's pretty clear that the other callers have a very dubious claim
      to ownership of the per-thread queue.  Do this is both frontend and
      backend code.
      
      Finally, be more careful about clearing our own error queue, so as to
      not cause these problems ourself.  It's possibly that control previously
      did not always reach SSLerrmessage(), where ERR_get_error() was supposed
      to be called to clear the queue's earliest code.  Make sure
      ERR_get_error() is always called, so as to spare other users of OpenSSL
      the possibility of similar problems caused by libpq (as opposed to
      problems caused by a third party OpenSSL library like PHP's OpenSSL
      extension).  Again, do this is both frontend and backend code.
      
      See bug #12799 and https://bugs.php.net/bug.php?id=68276
      
      Based on patches by Dave Vitek and Peter Eisentraut.
      
      From: Peter Geoghegan <pg@bowt.ie>
      e3a493ac
  16. May 06, 2016
    • Tom Lane's avatar
      Fix possible read past end of string in to_timestamp(). · 11247dd9
      Tom Lane authored
      to_timestamp() handles the TH/th format codes by advancing over two input
      characters, whatever those are.  It failed to notice whether there were
      two characters available to be skipped, making it possible to advance
      the pointer past the end of the input string and keep on parsing.
      A similar risk existed in the handling of "Y,YYY" format: it would advance
      over three characters after the "," whether or not three characters were
      available.
      
      In principle this might be exploitable to disclose contents of server
      memory.  But the security team concluded that it would be very hard to use
      that way, because the parsing loop would stop upon hitting any zero byte,
      and TH/th format codes can't be consecutive --- they have to follow some
      other format code, which would have to match whatever data is there.
      So it seems impractical to examine memory very much beyond the end of the
      input string via this bug; and the input string will always be in local
      memory not in disk buffers, making it unlikely that anything very
      interesting is close to it in a predictable way.  So this doesn't quite
      rise to the level of needing a CVE.
      
      Thanks to Wolf Roediger for reporting this bug.
      11247dd9
    • Tom Lane's avatar
      Update time zone data files to tzdata release 2016d. · 29d154e3
      Tom Lane authored
      DST law changes in Russia (Magadan, Tomsk regions) and Venezuela.
      Historical corrections for Russia.  There are new zone names Europe/Kirov
      and Asia/Tomsk reflecting the fact that these regions now have different
      time zone histories from adjacent regions.
      29d154e3
  17. May 04, 2016
  18. May 02, 2016
    • Tom Lane's avatar
      Fix configure's incorrect version tests for flex and perl. · 28e02b8f
      Tom Lane authored
      awk's equality-comparison operator is "==" not "=".  We got this right
      in many places, but not in configure's checks for supported version
      numbers of flex and perl.  It hadn't been noticed because unsupported
      versions are so old as to be basically extinct in the wild, and because
      the only consequence is whether or not a WARNING flies by during
      configure.
      
      Daniel Gustafsson noted the problem with respect to the test for flex,
      I found the other by reviewing other awk calls.
      28e02b8f
    • Heikki Linnakangas's avatar
      Remove unused macros. · 7ee15c05
      Heikki Linnakangas authored
      CHECK_PAGE_OFFSET_RANGE() has been unused forever.
      CHECK_RELATION_BLOCK_RANGE() has been unused in pgstatindex.c ever since
      bt_page_stats() and bt_page_items() functions were moved from pgstattuple
      to pageinspect module. It still exists in pageinspect/btreefuncs.c.
      
      Daniel Gustafsson
      7ee15c05
  19. Apr 30, 2016
    • Tom Lane's avatar
      Fix mishandling of equivalence-class tests in parameterized plans. · f02cb8c9
      Tom Lane authored
      Given a three-or-more-way equivalence class, such as X.Y = Y.Y = Z.Z,
      it was possible for the planner to omit one of the quals needed to
      enforce that all members of the equivalence class are actually equal.
      This only happened in the case of a parameterized join node for two
      of the relations, that is a plan tree like
      
      	Nested Loop
      	  ->  Scan X
      	  ->  Nested Loop
      	    ->  Scan Y
      	    ->  Scan Z
      	          Filter: Z.Z = X.X
      
      The eclass machinery normally expects to apply X.X = Y.Y when those
      two relations are joined, but in this shape of plan tree they aren't
      joined until the top node --- and, if the lower nested loop is marked
      as parameterized by X, the top node will assume that the relevant eclass
      condition(s) got pushed down into the lower node.  On the other hand,
      the scan of Z assumes that it's only responsible for constraining Z.Z
      to match any one of the other eclass members.  So one or another of
      the required quals sometimes fell between the cracks, depending on
      whether consideration of the eclass in get_joinrel_parampathinfo()
      for the lower nested loop chanced to generate X.X = Y.Y or X.X = Z.Z
      as the appropriate constraint there.  If it generated the latter,
      it'd erroneously suppose that the Z scan would take care of matters.
      To fix, force X.X = Y.Y to be generated and applied at that join node
      when this case occurs.
      
      This is *extremely* hard to hit in practice, because various planner
      behaviors conspire to mask the problem; starting with the fact that the
      planner doesn't really like to generate a parameterized plan of the
      above shape.  (It might have been impossible to hit it before we
      tweaked things to allow this plan shape for star-schema cases.)  Many
      thanks to Alexander Kirkouski for submitting a reproducible test case.
      
      The bug can be demonstrated in all branches back to 9.2 where parameterized
      paths were introduced, so back-patch that far.
      f02cb8c9
  20. Apr 28, 2016
    • Tom Lane's avatar
      Adjust DatumGetBool macro, this time for sure. · c563d97c
      Tom Lane authored
      Commit 23a41573 attempted to fix the DatumGetBool macro to ignore bits
      in a Datum that are to the left of the actual bool value.  But it did that
      by casting the Datum to bool; and on compilers that use C99 semantics for
      bool, that ends up being a whole-word test, not a 1-byte test.  This seems
      to be the true explanation for contrib/seg failing in VS2015.  To fix, use
      GET_1_BYTE() explicitly.  I think in the previous patch, I'd had some idea
      of not having to commit to bool being exactly 1 byte wide, but regardless
      of what the compiler's bool is, boolean columns and Datums are certainly
      1 byte wide.
      
      The previous fix was (eventually) back-patched into all active versions,
      so do likewise with this one.
      c563d97c
  21. Apr 23, 2016
    • Tom Lane's avatar
      Rename strtoi() to strtoint(). · 0f549128
      Tom Lane authored
      NetBSD has seen fit to invent a libc function named strtoi(), which
      conflicts with the long-established static functions of the same name in
      datetime.c and ecpg's interval.c.  While muttering darkly about intrusions
      on application namespace, we'll rename our functions to avoid the conflict.
      
      Back-patch to all supported branches, since this would affect attempts
      to build any of them on recent NetBSD.
      
      Thomas Munro
      0f549128
  22. Apr 22, 2016
    • Tom Lane's avatar
      Fix planner failure with full join in RHS of left join. · ad2d32b5
      Tom Lane authored
      Given a left join containing a full join in its righthand side, with
      the left join's joinclause referencing only one side of the full join
      (in a non-strict fashion, so that the full join doesn't get simplified),
      the planner could fail with "failed to build any N-way joins" or related
      errors.  This happened because the full join was seen as overlapping the
      left join's RHS, and then recent changes within join_is_legal() caused
      that function to conclude that the full join couldn't validly be formed.
      Rather than try to rejigger join_is_legal() yet more to allow this,
      I think it's better to fix initsplan.c so that the required join order
      is explicit in the SpecialJoinInfo data structure.  The previous coding
      there essentially ignored full joins, relying on the fact that we don't
      flatten them in the joinlist data structure to preserve their ordering.
      That's sufficient to prevent a wrong plan from being formed, but as this
      example shows, it's not sufficient to ensure that the right plan will
      be formed.  We need to work a bit harder to ensure that the right plan
      looks sane according to the SpecialJoinInfos.
      
      Per bug #14105 from Vojtech Rylko.  This was apparently induced by
      commit 8703059c (though now that I've seen it, I wonder whether there
      are related cases that could have failed before that); so back-patch
      to all active branches.  Unfortunately, that patch also went into 9.0,
      so this bug is a regression that won't be fixed in that branch.
      ad2d32b5
  23. Apr 21, 2016
    • Tom Lane's avatar
      Improve TranslateSocketError() to handle more Windows error codes. · b5ebc513
      Tom Lane authored
      The coverage was rather lean for cases that bind() or listen() might
      return.  Add entries for everything that there's a direct equivalent
      for in the set of Unix errnos that elog.c has heard of.
      b5ebc513
    • Tom Lane's avatar
      Remove dead code in win32.h. · d1e4ede7
      Tom Lane authored
      There's no longer a need for the MSVC-version-specific code stanza that
      forcibly redefines errno code symbols, because since commit 73838b52 we're
      unconditionally redefining them in the stanza before this one anyway.
      Now it's merely confusing and ugly, so get rid of it; and improve the
      comment that explains what's going on here.
      
      Although this is just cosmetic, back-patch anyway since I'm intending
      to back-patch some less-cosmetic changes in this same hunk of code.
      d1e4ede7
    • Tom Lane's avatar
      Provide errno-translation wrappers around bind() and listen() on Windows. · 6848827b
      Tom Lane authored
      Fix Windows builds to report something useful rather than "could not bind
      IPv4 socket: No error" when bind() fails.
      
      Back-patch of commits d1b7d487 and 22989a8e.
      
      Discussion: <4065.1452450340@sss.pgh.pa.us>
      6848827b
    • Tom Lane's avatar
      Fix ruleutils.c's dumping of ScalarArrayOpExpr containing an EXPR_SUBLINK. · c7c145e4
      Tom Lane authored
      When we shoehorned "x op ANY (array)" into the SQL syntax, we created a
      fundamental ambiguity as to the proper treatment of a sub-SELECT on the
      righthand side: perhaps what's meant is to compare x against each row of
      the sub-SELECT's result, or perhaps the sub-SELECT is meant as a scalar
      sub-SELECT that delivers a single array value whose members should be
      compared against x.  The grammar resolves it as the former case whenever
      the RHS is a select_with_parens, making the latter case hard to reach ---
      but you can get at it, with tricks such as attaching a no-op cast to the
      sub-SELECT.  Parse analysis would throw away the no-op cast, leaving a
      parsetree with an EXPR_SUBLINK SubLink directly under a ScalarArrayOpExpr.
      ruleutils.c was not clued in on this fine point, and would naively emit
      "x op ANY ((SELECT ...))", which would be parsed as the first alternative,
      typically leading to errors like "operator does not exist: text = text[]"
      during dump/reload of a view or rule containing such a construct.  To fix,
      emit a no-op cast when dumping such a parsetree.  This might well be
      exactly what the user wrote to get the construct accepted in the first
      place; and even if she got there with some other dodge, it is a valid
      representation of the parsetree.
      
      Per report from Karl Czajkowski.  He mentioned only a case involving
      RLS policies, but actually the problem is very old, so back-patch to
      all supported branches.
      
      Report: <20160421001832.GB7976@moraine.isi.edu>
      c7c145e4
    • Tom Lane's avatar
      Honor PGCTLTIMEOUT environment variable for pg_regress' startup wait. · 1b22368f
      Tom Lane authored
      In commit 2ffa8696 we made pg_ctl recognize an environment variable
      PGCTLTIMEOUT to set the default timeout for starting and stopping the
      postmaster.  However, pg_regress uses pg_ctl only for the "stop" end of
      that; it has bespoke code for starting the postmaster, and that code has
      historically had a hard-wired 60-second timeout.  Further buildfarm
      experience says it'd be a good idea if that timeout were also controlled
      by PGCTLTIMEOUT, so let's make it so.  Like the previous patch, back-patch
      to all active branches.
      
      Discussion: <13969.1461191936@sss.pgh.pa.us>
      1b22368f
  24. Apr 18, 2016
    • Tom Lane's avatar
      Further reduce the number of semaphores used under --disable-spinlocks. · b24f7e28
      Tom Lane authored
      Per discussion, there doesn't seem to be much value in having
      NUM_SPINLOCK_SEMAPHORES set to 1024: under any scenario where you are
      running more than a few backends concurrently, you really had better have a
      real spinlock implementation if you want tolerable performance.  And 1024
      semaphores is a sizable fraction of the system-wide SysV semaphore limit
      on many platforms.  Therefore, reduce this setting's default value to 128
      to make it less likely to cause out-of-semaphores problems.
      b24f7e28
    • Tom Lane's avatar
      Fix --disable-spinlocks in 9.2 and 9.3 branches. · 37f30b25
      Tom Lane authored
      My back-patch of the 9.4-era commit 44cd47c1 into 9.2 and 9.3 fixed
      HPPA builds as expected, but it broke --disable-spinlocks builds, because
      the dummy spinlock is initialized before the underlying semaphore
      infrastructure is alive.  In 9.4 and up this works because of commit
      daa7527a, which decoupled initialization of an slock_t variable
      from access to the actual system semaphore object.  The best solution
      seems to be to back-port that patch, which should be a net win anyway
      because it improves the usability of --disable-spinlocks builds in the
      older branches; and it's been out long enough now to not be worrisome
      from a stability perspective.
      37f30b25
  25. Apr 16, 2016
  26. Apr 15, 2016
    • Tom Lane's avatar
      Sync 9.2 and 9.3 versions of barrier.h with 9.4's version. · d7dbc882
      Tom Lane authored
      We weren't particularly maintaining barrier.h before 9.4, because nothing
      was using it in those branches.  Well, nothing until commit 37de8de9 got
      back-patched.  That broke 9.2 and 9.3 for some non-mainstream platforms
      that we haven't been testing in the buildfarm, including icc on ia64,
      HPPA, and Alpha.
      
      This commit effectively back-patches commits e5592c61, 89779bf2,
      and 747ca669, though I did it just by copying the file (less copyright
      date updates) rather than by cherry-picking those commits.
      
      Per an attempt to run gaur and pademelon over old branches they've
      not been run on since ~2013.
      d7dbc882
Loading