Skip to content
Snippets Groups Projects
  1. Nov 10, 2015
    • Tom Lane's avatar
      Improve our workaround for 'TeX capacity exceeded' in building PDF files. · e12a99c8
      Tom Lane authored
      In commit a5ec86a7 I wrote a quick hack
      that reduced the number of TeX string pool entries created while converting
      our documentation to PDF form.  That held the fort for awhile, but as of
      HEAD we're back up against the same limitation.  It turns out that the
      original coding of \FlowObjectSetup actually results in *three* string pool
      entries being generated for every "flow object" (that is, potential
      cross-reference target) in the documentation, and my previous hack only got
      rid of one of them.  With a little more care, we can reduce the string
      count to one per flow object plus one per actually-cross-referenced flow
      object (about 115000 + 5000 as of current HEAD); that should work until
      the documentation volume roughly doubles from where it is today.
      
      As a not-incidental side benefit, this change also causes pdfjadetex to
      stop emitting unreferenced hyperlink anchors (bookmarks) into the PDF file.
      It had been making one willy-nilly for every flow object; now it's just one
      per actually-cross-referenced object.  This results in close to a 2X
      savings in PDF file size.  We will still want to run the output through
      "jpdftweak" to get it to be compressed; but we no longer need removal of
      unreferenced bookmarks, so we might be able to find a quicker tool for
      that step.
      
      Although the failure only affects HEAD and US-format output at the moment,
      9.5 cannot be more than a few pages short of failing likewise, so it
      will inevitably fail after a few rounds of minor-version release notes.
      I don't have a lot of faith that we'll never hit the limit in the older
      branches; and anyway it would be nice to get rid of jpdftweak across the
      board.  Therefore, back-patch to all supported branches.
      e12a99c8
  2. Nov 08, 2015
    • Noah Misch's avatar
      Don't connect() to a wildcard address in test_postmaster_connection(). · 99027350
      Noah Misch authored
      At least OpenBSD, NetBSD, and Windows don't support it.  This repairs
      pg_ctl for listen_addresses='0.0.0.0' and listen_addresses='::'.  Since
      pg_ctl prefers to test a Unix-domain socket, Windows users are most
      likely to need this change.  Back-patch to 9.1 (all supported versions).
      This could change pg_ctl interaction with loopback-interface firewall
      rules.  Therefore, in 9.4 and earlier (released branches), activate the
      change only on known-affected platforms.
      
      Reported (bug #13611) and designed by Kondo Yuta.
      99027350
  3. Nov 07, 2015
    • Tom Lane's avatar
      Fix enforcement of restrictions inside regexp lookaround constraints. · bfb10db8
      Tom Lane authored
      Lookahead and lookbehind constraints aren't allowed to contain backrefs,
      and parentheses within them are always considered non-capturing.  Or so
      says the manual.  But the regexp parser forgot about these rules once
      inside a parenthesized subexpression, so that constructs like (\w)(?=(\1))
      were accepted (but then not correctly executed --- a case like this acted
      like (\w)(?=\w), without any enforcement that the two \w's match the same
      text).  And in (?=((foo))) the innermost parentheses would be counted as
      capturing parentheses, though no text would ever be captured for them.
      
      To fix, properly pass down the "type" argument to the recursive invocation
      of parse().
      
      Back-patch to all supported branches; it was agreed that silent
      misexecution of such patterns is worse than throwing an error, even though
      new errors in minor releases are generally not desirable.
      bfb10db8
  4. Oct 31, 2015
    • Kevin Grittner's avatar
      Fix serialization anomalies due to race conditions on INSERT. · caff7fc3
      Kevin Grittner authored
      On insert the CheckForSerializableConflictIn() test was performed
      before the page(s) which were going to be modified had been locked
      (with an exclusive buffer content lock).  If another process
      acquired a relation SIReadLock on the heap and scanned to a page on
      which an insert was going to occur before the page was so locked,
      a rw-conflict would be missed, which could allow a serialization
      anomaly to be missed.  The window between the check and the page
      lock was small, so the bug was generally not noticed unless there
      was high concurrency with multiple processes inserting into the
      same table.
      
      This was reported by Peter Bailis as bug #11732, by Sean Chittenden
      as bug #13667, and by others.
      
      The race condition was eliminated in heap_insert() by moving the
      check down below the acquisition of the buffer lock, which had been
      the very next statement.  Because of the loop locking and unlocking
      multiple buffers in heap_multi_insert() a check was added after all
      inserts were completed.  The check before the start of the inserts
      was left because it might avoid a large amount of work to detect a
      serialization anomaly before performing the all of the inserts and
      the related WAL logging.
      
      While investigating this bug, other SSI bugs which were even harder
      to hit in practice were noticed and fixed, an unnecessary check
      (covered by another check, so redundant) was removed from
      heap_update(), and comments were improved.
      
      Back-patch to all supported branches.
      
      Kevin Grittner and Thomas Munro
      caff7fc3
  5. Oct 20, 2015
    • Noah Misch's avatar
      Fix back-patch of commit 8e3b4d9d. · 887d9142
      Noah Misch authored
      master emits an extra context message compared to 9.5 and earlier.
      887d9142
    • Noah Misch's avatar
      Eschew "RESET statement_timeout" in tests. · 934fdaac
      Noah Misch authored
      Instead, use transaction abort.  Given an unlucky bout of latency, the
      timeout would cancel the RESET itself.  Buildfarm members gharial,
      lapwing, mereswine, shearwater, and sungazer witness that.  Back-patch
      to 9.1 (all supported versions).  The query_canceled test still could
      timeout before entering its subtransaction; for whatever reason, that
      has yet to happen on the buildfarm.
      934fdaac
  6. Oct 19, 2015
    • Tom Lane's avatar
      Fix incorrect handling of lookahead constraints in pg_regprefix(). · 05e62ff5
      Tom Lane authored
      pg_regprefix was doing nothing with lookahead constraints, which would
      be fine if it were the right kind of nothing, but it isn't: we have to
      terminate our search for a fixed prefix, not just pretend the LACON arc
      isn't there.  Otherwise, if the current state has both a LACON outarc and a
      single plain-color outarc, we'd falsely conclude that the color represents
      an addition to the fixed prefix, and generate an extracted index condition
      that restricts the indexscan too much.  (See added regression test case.)
      
      Terminating the search is conservative: we could traverse the LACON arc
      (thus assuming that the constraint can be satisfied at runtime) and then
      examine the outarcs of the linked-to state.  But that would be a lot more
      work than it seems worth, because writing a LACON followed by a single
      plain character is a pretty silly thing to do.
      
      This makes a difference only in rather contrived cases, but it's a bug,
      so back-patch to all supported branches.
      05e62ff5
  7. Oct 18, 2015
  8. Oct 16, 2015
    • Tom Lane's avatar
      Miscellaneous cleanup of regular-expression compiler. · 2419ab8a
      Tom Lane authored
      Revert our previous addition of "all" flags to copyins() and copyouts();
      they're no longer needed, and were never anything but an unsightly hack.
      
      Improve a couple of infelicities in the REG_DEBUG code for dumping
      the NFA data structure, including adding code to count the total
      number of states and arcs.
      
      Add a couple of missed error checks.
      
      Add some more documentation in the README file, and some regression tests
      illustrating cases that exceeded the state-count limit and/or took
      unreasonable amounts of time before this set of patches.
      
      Back-patch to all supported branches.
      2419ab8a
    • Tom Lane's avatar
      Improve memory-usage accounting in regular-expression compiler. · 4e4610a8
      Tom Lane authored
      This code previously counted the number of NFA states it created, and
      complained if a limit was exceeded, so as to prevent bizarre regex patterns
      from consuming unreasonable time or memory.  That's fine as far as it went,
      but the code paid no attention to how many arcs linked those states.  Since
      regexes can be contrived that have O(N) states but will need O(N^2) arcs
      after fixempties() processing, it was still possible to blow out memory,
      and take a long time doing it too.  To fix, modify the bookkeeping to count
      space used by both states and arcs.
      
      I did not bother with including the "color map" in the accounting; it
      can only grow to a few megabytes, which is not a lot in comparison to
      what we're allowing for states+arcs (about 150MB on 64-bit machines
      or half that on 32-bit machines).
      
      Looking at some of the larger real-world regexes captured in the Tcl
      regression test suite suggests that the most that is likely to be needed
      for regexes found in the wild is under 10MB, so I believe that the current
      limit has enough headroom to make it okay to keep it as a hard-wired limit.
      
      In connection with this, redefine REG_ETOOBIG as meaning "regular
      expression is too complex"; the previous wording of "nfa has too many
      states" was already somewhat inapropos because of the error code's use
      for stack depth overrun, and it was not very user-friendly either.
      
      Back-patch to all supported branches.
      4e4610a8
    • Tom Lane's avatar
      Improve performance of pullback/pushfwd in regular-expression compiler. · a257b808
      Tom Lane authored
      The previous coding would create a new intermediate state every time it
      wanted to interchange the ordering of two constraint arcs.  Certain regex
      features such as \Y can generate large numbers of parallel constraint arcs,
      and if we needed to reorder the results of that, we created unreasonable
      numbers of intermediate states.  To improve matters, keep a list of
      already-created intermediate states associated with the state currently
      being considered by the outer loop; we can re-use such states to place all
      the new arcs leading to the same destination or source.
      
      I also took the trouble to redefine push() and pull() to have a less risky
      API: they no longer delete any state or arc that the caller might possibly
      have a pointer to, except for the specifically-passed constraint arc.
      This reduces the risk of re-introducing the same type of error seen in
      the failed patch for CVE-2007-4772.
      
      Back-patch to all supported branches.
      a257b808
    • Tom Lane's avatar
      Improve performance of fixempties() pass in regular-expression compiler. · 18b032f8
      Tom Lane authored
      The previous coding took something like O(N^4) time to fully process a
      chain of N EMPTY arcs.  We can't really do much better than O(N^2) because
      we have to insert about that many arcs, but we can do lots better than
      what's there now.  The win comes partly from using mergeins() to amortize
      de-duplication of arcs across multiple source states, and partly from
      exploiting knowledge of the ordering of arcs for each state to avoid
      looking at arcs we don't need to consider during the scan.  We do have
      to be a bit careful of the possible reordering of arcs introduced by
      the sort-merge coding of the previous commit, but that's not hard to
      deal with.
      
      Back-patch to all supported branches.
      18b032f8
    • Tom Lane's avatar
      Fix O(N^2) performance problems in regular-expression compiler. · a2ad467a
      Tom Lane authored
      Change the singly-linked in-arc and out-arc lists to be doubly-linked,
      so that arc deletion is constant time rather than having worst-case time
      proportional to the number of other arcs on the connected states.
      
      Modify the bulk arc transfer operations copyins(), copyouts(), moveins(),
      moveouts() so that they use a sort-and-merge algorithm whenever there's
      more than a small number of arcs to be copied or moved.  The previous
      method is O(N^2) in the number of arcs involved, because it performs
      duplicate checking independently for each copied arc.  The new method may
      change the ordering of existing arcs for the destination state, but nothing
      really cares about that.
      
      Provide another bulk arc copying method mergeins(), which is unused as
      of this commit but is needed for the next one.  It basically is like
      copyins(), but the source arcs might not all come from the same state.
      
      Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort()
      call.
      
      These changes greatly improve the performance of regex compilation for
      large or complex regexes, at the cost of extra space for arc storage during
      compilation.  The original tradeoff was probably fine when it was made, but
      now we care more about speed and less about memory consumption.
      
      Back-patch to all supported branches.
      a2ad467a
    • Tom Lane's avatar
      Fix regular-expression compiler to handle loops of constraint arcs. · 83c34825
      Tom Lane authored
      It's possible to construct regular expressions that contain loops of
      constraint arcs (that is, ^ $ AHEAD BEHIND or LACON arcs).  There's no use
      in fully traversing such a loop at execution, since you'd just end up in
      the same NFA state without having consumed any input.  Worse, such a loop
      leads to infinite looping in the pullback/pushfwd stage of compilation,
      because we keep pushing or pulling the same constraints around the loop
      in a vain attempt to move them to the pre or post state.  Such looping was
      previously recognized in CVE-2007-4772; but the fix only handled the case
      of trivial single-state loops (that is, a constraint arc leading back to
      its source state) ... and not only that, it was incorrect even for that
      case, because it broke the admittedly-not-very-clearly-stated API contract
      of the pull() and push() subroutines.  The first two regression test cases
      added by this commit exhibit patterns that result in assertion failures
      because of that (though there seem to be no ill effects in non-assert
      builds).  The other new test cases exhibit multi-state constraint loops;
      in an unpatched build they will run until the NFA state-count limit is
      exceeded.
      
      To fix, remove the code added for CVE-2007-4772, and instead create a
      general-purpose constraint-loop-breaking phase of regex compilation that
      executes before we do pullback/pushfwd.  Since we never need to traverse
      a constraint loop fully, we can just break the loop at any chosen spot,
      if we add clone states that can replicate any sequence of arc transitions
      that would've traversed just part of the loop.
      
      Also add some commentary clarifying why we have to have all these
      machinations in the first place.
      
      This class of problems has been known for some time --- we had a report
      from Marc Mamin about two years ago, for example, and there are related
      complaints in the Tcl bug tracker.  I had discussed a fix of this kind
      off-list with Henry Spencer, but didn't get around to doing something
      about it until the issue was rediscovered by Greg Stark recently.
      
      Back-patch to all supported branches.
      83c34825
  9. Oct 13, 2015
    • Tom Lane's avatar
      On Windows, ensure shared memory handle gets closed if not being used. · 39cd1bdb
      Tom Lane authored
      Postmaster child processes that aren't supposed to be attached to shared
      memory were not bothering to close the shared memory mapping handle they
      inherit from the postmaster process.  That's mostly harmless, since the
      handle vanishes anyway when the child process exits -- but the syslogger
      process, if used, doesn't get killed and restarted during recovery from a
      backend crash.  That meant that Windows doesn't see the shared memory
      mapping as becoming free, so it doesn't delete it and the postmaster is
      unable to create a new one, resulting in failure to recover from crashes
      whenever logging_collector is turned on.
      
      Per report from Dmitry Vasilyev.  It's a bit astonishing that we'd not
      figured this out long ago, since it's been broken from the very beginnings
      of out native Windows support; probably some previously-unexplained trouble
      reports trace to this.
      
      A secondary problem is that on Cygwin (perhaps only in older versions?),
      exec() may not detach from the shared memory segment after all, in which
      case these child processes did remain attached to shared memory, posing
      the risk of an unexpected shared memory clobber if they went off the rails
      somehow.  That may be a long-gone bug, but we can deal with it now if it's
      still live, by detaching within the infrastructure introduced here to deal
      with closing the handle.
      
      Back-patch to all supported branches.
      
      Tom Lane and Amit Kapila
      39cd1bdb
    • Tom Lane's avatar
      Fix "pg_ctl start -w" to test child process status directly. · 250108b6
      Tom Lane authored
      pg_ctl start with -w previously relied on a heuristic that the postmaster
      would surely always manage to create postmaster.pid within five seconds.
      Unfortunately, that fails much more often than we would like on some of the
      slower, more heavily loaded buildfarm members.
      
      We have known for quite some time that we could remove the need for that
      heuristic on Unix by using fork/exec instead of system() to launch the
      postmaster.  This allows us to know the exact PID of the postmaster, which
      allows near-certain verification that the postmaster.pid file is the one
      we want and not a leftover, and it also lets us use waitpid() to detect
      reliably whether the child postmaster has exited or not.
      
      What was blocking this change was not wanting to rewrite the Windows
      version of start_postmaster() to avoid use of CMD.EXE.  That's doable
      in theory but would require fooling about with stdout/stderr redirection,
      and getting the handling of quote-containing postmaster switches to
      stay the same might be rather ticklish.  However, we realized that
      we don't have to do that to fix the problem, because we can test
      whether the shell process has exited as a proxy for whether the
      postmaster is still alive.  That doesn't allow an exact check of the
      PID in postmaster.pid, but we're no worse off than before in that
      respect; and we do get to get rid of the heuristic about how long the
      postmaster might take to create postmaster.pid.
      
      On Unix, this change means that a second "pg_ctl start -w" immediately
      after another such command will now reliably fail, whereas previously
      it would succeed if done within two seconds of the earlier command.
      Since that's a saner behavior anyway, it's fine.  On Windows, the case can
      still succeed within the same time window, since pg_ctl can't tell that the
      earlier postmaster's postmaster.pid isn't the pidfile it is looking for.
      To ensure stable test results on Windows, we can insert a short sleep into
      the test script for pg_ctl, ensuring that the existing pidfile looks stale.
      This hack can be removed if we ever do rewrite start_postmaster(), but that
      no longer seems like a high-priority thing to do.
      
      Back-patch to all supported versions, both because the current behavior
      is buggy and because we must do that if we want the buildfarm failures
      to go away.
      
      Tom Lane and Michael Paquier
      250108b6
  10. Oct 07, 2015
    • Tom Lane's avatar
      Improve documentation of the role-dropping process. · 53951058
      Tom Lane authored
      In general one may have to run both REASSIGN OWNED and DROP OWNED to get
      rid of all the dependencies of a role to be dropped.  This was alluded to
      in the REASSIGN OWNED man page, but not really spelled out in full; and in
      any case the procedure ought to be documented in a more prominent place
      than that.  Add a section to the "Database Roles" chapter explaining this,
      and do a bit of wordsmithing in the relevant commands' man pages.
      53951058
  11. Oct 06, 2015
    • Tom Lane's avatar
      Perform an immediate shutdown if the postmaster.pid file is removed. · 3d10f397
      Tom Lane authored
      The postmaster now checks every minute or so (worst case, at most two
      minutes) that postmaster.pid is still there and still contains its own PID.
      If not, it performs an immediate shutdown, as though it had received
      SIGQUIT.
      
      The original goal behind this change was to ensure that failed buildfarm
      runs would get fully cleaned up, even if the test scripts had left a
      postmaster running, which is not an infrequent occurrence.  When the
      buildfarm script removes a test postmaster's $PGDATA directory, its next
      check on postmaster.pid will fail and cause it to exit.  Previously, manual
      intervention was often needed to get rid of such orphaned postmasters,
      since they'd block new test postmasters from obtaining the expected socket
      address.
      
      However, by checking postmaster.pid and not something else, we can provide
      additional robustness: manual removal of postmaster.pid is a frequent DBA
      mistake, and now we can at least limit the damage that will ensue if a new
      postmaster is started while the old one is still alive.
      
      Back-patch to all supported branches, since we won't get the desired
      improvement in buildfarm reliability otherwise.
      3d10f397
  12. Oct 05, 2015
    • Tom Lane's avatar
      Stamp 9.2.14. · 69157086
      Tom Lane authored
    • Peter Eisentraut's avatar
      doc: Update URLs of external projects · d3ff94d8
      Peter Eisentraut authored
      d3ff94d8
    • Peter Eisentraut's avatar
      Translation updates · f177e1ba
      Peter Eisentraut authored
      Source-Git-URL: git://git.postgresql.org/git/pgtranslation/messages.git
      Source-Git-Hash: d8bd45466e3980b5ab4582ff1705fcd1fff42908
      f177e1ba
    • Tom Lane's avatar
      Last-minute updates for release notes. · dd5502a8
      Tom Lane authored
      Add entries for security and not-quite-security issues.
      
      Security: CVE-2015-5288, CVE-2015-5289
      dd5502a8
    • Andres Freund's avatar
      Remove outdated comment about relation level autovacuum freeze limits. · 6cb5bdec
      Andres Freund authored
      The documentation for the autovacuum_multixact_freeze_max_age and
      autovacuum_freeze_max_age relation level parameters contained:
      "Note that while you can set autovacuum_multixact_freeze_max_age very
      small, or even zero, this is usually unwise since it will force frequent
      vacuuming."
      which hasn't been true since these options were made relation options,
      instead of residing in the pg_autovacuum table (834a6da4).
      
      Remove the outdated sentence. Even the lowered limits from 2596d705 are
      high enough that this doesn't warrant calling out the risk in the CREATE
      TABLE docs.
      
      Per discussion with Tom Lane and Alvaro Herrera
      
      Discussion: 26377.1443105453@sss.pgh.pa.us
      Backpatch: 9.0- (in parts)
      6cb5bdec
    • Noah Misch's avatar
      Prevent stack overflow in query-type functions. · ea68c221
      Noah Misch authored
      The tsquery, ltxtquery and query_int data types have a common ancestor.
      Having acquired check_stack_depth() calls independently, each was
      missing at least one call.  Back-patch to 9.0 (all supported versions).
      ea68c221
    • Noah Misch's avatar
      Prevent stack overflow in container-type functions. · 5e43130b
      Noah Misch authored
      A range type can name another range type as its subtype, and a record
      type can bear a column of another record type.  Consequently, functions
      like range_cmp() and record_recv() are recursive.  Functions at risk
      include operator family members and referents of pg_type regproc
      columns.  Treat as recursive any such function that looks up and calls
      the same-purpose function for a record column type or the range subtype.
      Back-patch to 9.0 (all supported versions).
      
      An array type's element type is never itself an array type, so array
      functions are unaffected.  Recursion depth proportional to array
      dimensionality, found in array_dim_to_jsonb(), is fine thanks to MAXDIM.
      5e43130b
    • Noah Misch's avatar
      Prevent stack overflow in json-related functions. · 8dacb29c
      Noah Misch authored
      Sufficiently-deep recursion heretofore elicited a SIGSEGV.  If an
      application constructs PostgreSQL json or jsonb values from arbitrary
      user input, application users could have exploited this to terminate all
      active database connections.  That applies to 9.3, where the json parser
      adopted recursive descent, and later versions.  Only row_to_json() and
      array_to_json() were at risk in 9.2, both in a non-security capacity.
      Back-patch to 9.2, where the json type was introduced.
      
      Oskari Saarenmaa, reviewed by Michael Paquier.
      
      Security: CVE-2015-5289
      8dacb29c
    • Noah Misch's avatar
      pgcrypto: Detect and report too-short crypt() salts. · 56232f98
      Noah Misch authored
      Certain short salts crashed the backend or disclosed a few bytes of
      backend memory.  For existing salt-induced error conditions, emit a
      message saying as much.  Back-patch to 9.0 (all supported versions).
      
      Josh Kupershmidt
      
      Security: CVE-2015-5288
      56232f98
    • Andres Freund's avatar
      Re-Align *_freeze_max_age reloption limits with corresponding GUC limits. · e07cfef3
      Andres Freund authored
      In 020235a5 I lowered the autovacuum_*freeze_max_age minimums to
      allow for easier testing of wraparounds. I did not touch the
      corresponding per-table limits. While those don't matter for the purpose
      of wraparound, it seems more consistent to lower them as well.
      
      It's noteworthy that the previous reloption lower limit for
      autovacuum_multixact_freeze_max_age was too high by one magnitude, even
      before 020235a5.
      
      Discussion: 26377.1443105453@sss.pgh.pa.us
      Backpatch: back to 9.0 (in parts), like the prior patch
      e07cfef3
    • Tom Lane's avatar
  13. Oct 04, 2015
    • Tom Lane's avatar
      Further twiddling of nodeHash.c hashtable sizing calculation. · ebc7d928
      Tom Lane authored
      On reflection, the submitted patch didn't really work to prevent the
      request size from exceeding MaxAllocSize, because of the fact that we'd
      happily round nbuckets up to the next power of 2 after we'd limited it to
      max_pointers.  The simplest way to enforce the limit correctly is to
      round max_pointers down to a power of 2 when it isn't one already.
      
      (Note that the constraint to INT_MAX / 2, if it were doing anything useful
      at all, is properly applied after that.)
      ebc7d928
    • Tom Lane's avatar
      Fix possible "invalid memory alloc request size" failure in nodeHash.c. · fd3e3cf5
      Tom Lane authored
      Limit the size of the hashtable pointer array to not more than
      MaxAllocSize.  We've seen reports of failures due to this in HEAD/9.5,
      and it seems possible in older branches as well.  The change in
      NTUP_PER_BUCKET in 9.5 may have made the problem more likely, but
      surely it didn't introduce it.
      
      Tomas Vondra, slightly modified by me
      fd3e3cf5
  14. Oct 03, 2015
  15. Oct 02, 2015
    • Tom Lane's avatar
      Add recursion depth protection to LIKE matching. · 57bf7b54
      Tom Lane authored
      Since MatchText() recurses, it could in principle be driven to stack
      overflow, although quite a long pattern would be needed.
      57bf7b54
    • Tom Lane's avatar
      Add recursion depth protections to regular expression matching. · a0c089f3
      Tom Lane authored
      Some of the functions in regex compilation and execution recurse, and
      therefore could in principle be driven to stack overflow.  The Tcl crew
      has seen this happen in practice in duptraverse(), though their fix was
      to put in a hard-wired limit on the number of recursive levels, which is
      not too appetizing --- fortunately, we have enough infrastructure to check
      the actually available stack.  Greg Stark has also seen it in other places
      while fuzz testing on a machine with limited stack space.  Let's put guards
      in to prevent crashes in all these places.
      
      Since the regex code would leak memory if we simply threw elog(ERROR),
      we have to introduce an API that checks for stack depth without throwing
      such an error.  Fortunately that's not difficult.
      a0c089f3
    • Tom Lane's avatar
      Fix potential infinite loop in regular expression execution. · 483bbc9f
      Tom Lane authored
      In cfindloop(), if the initial call to shortest() reports that a
      zero-length match is possible at the current search start point, but then
      it is unable to construct any actual match to that, it'll just loop around
      with the same start point, and thus make no progress.  We need to force the
      start point to be advanced.  This is safe because the loop over "begin"
      points has already tried and failed to match starting at "close", so there
      is surely no need to try that again.
      
      This bug was introduced in commit e2bd9049,
      wherein we allowed continued searching after we'd run out of match
      possibilities, but evidently failed to think hard enough about exactly
      where we needed to search next.
      
      Because of the way this code works, such a match failure is only possible
      in the presence of backrefs --- otherwise, shortest()'s judgment that a
      match is possible should always be correct.  That probably explains how
      come the bug has escaped detection for several years.
      
      The actual fix is a one-liner, but I took the trouble to add/improve some
      comments related to the loop logic.
      
      After fixing that, the submitted test case "()*\1" didn't loop anymore.
      But it reported failure, though it seems like it ought to match a
      zero-length string; both Tcl and Perl think it does.  That seems to be from
      overenthusiastic optimization on my part when I rewrote the iteration match
      logic in commit 173e29aa: we can't just
      "declare victory" for a zero-length match without bothering to set match
      data for capturing parens inside the iterator node.
      
      Per fuzz testing by Greg Stark.  The first part of this is a bug in all
      supported branches, and the second part is a bug since 9.2 where the
      iteration rewrite happened.
      483bbc9f
    • Tom Lane's avatar
      Add some more query-cancel checks to regular expression matching. · 2d51f55f
      Tom Lane authored
      Commit 9662143f added infrastructure to
      allow regular-expression operations to be terminated early in the event
      of SIGINT etc.  However, fuzz testing by Greg Stark disclosed that there
      are still cases where regex compilation could run for a long time without
      noticing a cancel request.  Specifically, the fixempties() phase never
      adds new states, only new arcs, so it doesn't hit the cancel check I'd put
      in newstate().  Add one to newarc() as well to cover that.
      
      Some experimentation of my own found that regex execution could also run
      for a long time despite a pending cancel.  We'd put a high-level cancel
      check into cdissect(), but there was none inside the core text-matching
      routines longest() and shortest().  Ordinarily those inner loops are very
      very fast ... but in the presence of lookahead constraints, not so much.
      As a compromise, stick a cancel check into the stateset cache-miss
      function, which is enough to guarantee a cancel check at least once per
      lookahead constraint test.
      
      Making this work required more attention to error handling throughout the
      regex executor.  Henry Spencer had apparently originally intended longest()
      and shortest() to be incapable of incurring errors while running, so
      neither they nor their subroutines had well-defined error reporting
      behaviors.  However, that was already broken by the lookahead constraint
      feature, since lacon() can surely suffer an out-of-memory failure ---
      which, in the code as it stood, might never be reported to the user at all,
      but just silently be treated as a non-match of the lookahead constraint.
      Normalize all that by inserting explicit error tests as needed.  I took the
      opportunity to add some more comments to the code, too.
      
      Back-patch to all supported branches, like the previous patch.
      2d51f55f
    • Tom Lane's avatar
      Docs: add disclaimer about hazards of using regexps from untrusted sources. · 52511fd6
      Tom Lane authored
      It's not terribly hard to devise regular expressions that take large
      amounts of time and/or memory to process.  Recent testing by Greg Stark has
      also shown that machines with small stack limits can be driven to stack
      overflow by suitably crafted regexps.  While we intend to fix these things
      as much as possible, it's probably impossible to eliminate slow-execution
      cases altogether.  In any case we don't want to treat such things as
      security issues.  The history of that code should already discourage
      prudent DBAs from allowing execution of regexp patterns coming from
      possibly-hostile sources, but it seems like a good idea to warn about the
      hazard explicitly.
      
      Currently, similar_escape() allows access to enough of the underlying
      regexp behavior that the warning has to apply to SIMILAR TO as well.
      We might be able to make it safer if we tightened things up to allow only
      SQL-mandated capabilities in SIMILAR TO; but that would be a subtly
      non-backwards-compatible change, so it requires discussion and probably
      could not be back-patched.
      
      Per discussion among pgsql-security list.
      52511fd6
  16. Oct 01, 2015
    • Tom Lane's avatar
      Fix pg_dump to handle inherited NOT VALID check constraints correctly. · 3756c65a
      Tom Lane authored
      This case seems to have been overlooked when unvalidated check constraints
      were introduced, in 9.2.  The code would attempt to dump such constraints
      over again for each child table, even though adding them to the parent
      table is sufficient.
      
      In 9.2 and 9.3, also fix contrib/pg_upgrade/Makefile so that the "make
      clean" target fully cleans up after a failed test.  This evidently got
      dealt with at some point in 9.4, but it wasn't back-patched.  I ran into
      it while testing this fix ...
      
      Per bug #13656 from Ingmar Brouns.
      3756c65a
    • Tom Lane's avatar
      Fix documentation error in commit 8703059c. · c4a1039f
      Tom Lane authored
      Etsuro Fujita spotted a thinko in the README commentary.
      c4a1039f
    • Tom Lane's avatar
      Improve LISTEN startup time when there are many unread notifications. · e4c00750
      Tom Lane authored
      If some existing listener is far behind, incoming new listener sessions
      would start from that session's read pointer and then need to advance over
      many already-committed notification messages, which they have no interest
      in.  This was expensive in itself and also thrashed the pg_notify SLRU
      buffers a lot more than necessary.  We can improve matters considerably
      in typical scenarios, without much added cost, by starting from the
      furthest-ahead read pointer, not the furthest-behind one.  We do have to
      consider only sessions in our own database when doing this, which requires
      an extra field in the data structure, but that's a pretty small cost.
      
      Back-patch to 9.0 where the current LISTEN/NOTIFY logic was introduced.
      
      Matt Newell, slightly adjusted by me
      e4c00750
Loading