Skip to content
Snippets Groups Projects
  1. Oct 02, 2015
    • 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
  2. 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
  3. Sep 29, 2015
    • Tom Lane's avatar
      Fix plperl to handle non-ASCII error message texts correctly. · aae40cf1
      Tom Lane authored
      We were passing error message texts to croak() verbatim, which turns out
      not to work if the text contains non-ASCII characters; Perl mangles their
      encoding, as reported in bug #13638 from Michal Leinweber.  To fix, convert
      the text into a UTF8-encoded SV first.
      
      It's hard to test this without risking failures in different database
      encodings; but we can follow the lead of plpython, which is already
      assuming that no-break space (U+00A0) has an equivalent in all encodings
      we care about running the regression tests in (cf commit 2dfa15de).
      
      Back-patch to 9.1.  The code is quite different in 9.0, and anyway it seems
      too risky to put something like this into 9.0's final minor release.
      
      Alex Hunsaker, with suggestions from Tim Bunce and Tom Lane
      aae40cf1
    • Andrew Dunstan's avatar
      Fix compiler warning about unused function in non-readline case. · a959db8a
      Andrew Dunstan authored
      Backpatch to all live branches to keep the code in sync.
      a959db8a
  4. Sep 25, 2015
    • Tom Lane's avatar
      Further fix for psql's code for locale-aware formatting of numeric output. · 80fa5421
      Tom Lane authored
      (Third time's the charm, I hope.)
      
      Additional testing disclosed that this code could mangle already-localized
      output from the "money" datatype.  We can't very easily skip applying it
      to "money" values, because the logic is tied to column right-justification
      and people expect "money" output to be right-justified.  Short of
      decoupling that, we can fix it in what should be a safe enough way by
      testing to make sure the string doesn't contain any characters that would
      not be expected in plain numeric output.
      80fa5421
    • Tom Lane's avatar
      Further fix for psql's code for locale-aware formatting of numeric output. · 60617d7d
      Tom Lane authored
      On closer inspection, those seemingly redundant atoi() calls were not so
      much inefficient as just plain wrong: the author of this code either had
      not read, or had not understood, the POSIX specification for localeconv().
      The grouping field is *not* a textual digit string but separate integers
      encoded as chars.
      
      We'll follow the existing code as well as the backend's cash.c in only
      honoring the first group width, but let's at least honor it correctly.
      
      This doesn't actually result in any behavioral change in any of the
      locales I have installed on my Linux box, which may explain why nobody's
      complained; grouping width 3 is close enough to universal that it's barely
      worth considering other cases.  Still, wrong is wrong, so back-patch.
      60617d7d
    • Tom Lane's avatar
      Fix psql's code for locale-aware formatting of numeric output. · 596c9e9e
      Tom Lane authored
      This code did the wrong thing entirely for numbers with an exponent
      but no decimal point (e.g., '1e6'), as reported by Jeff Janes in
      bug #13636.  More generally, it made lots of unverified assumptions
      about what the input string could possibly look like.  Rearrange so
      that it only fools with leading digits that it's directly verified
      are there, and an immediately adjacent decimal point.  While at it,
      get rid of some useless inefficiencies, like converting the grouping
      count string to integer over and over (and over).
      
      This has been broken for a long time, so back-patch to all supported
      branches.
      596c9e9e
  5. Sep 24, 2015
    • Andres Freund's avatar
      Lower *_freeze_max_age minimum values. · f12932dd
      Andres Freund authored
      The old minimum values are rather large, making it time consuming to
      test related behaviour. Additionally the current limits, especially for
      multixacts, can be problematic in space-constrained systems. 10000000
      multixacts can contain a lot of members.
      
      Since there's no good reason for the current limits, lower them a good
      bit. Setting them to 0 would be a bad idea, triggering endless vacuums,
      so still retain a limit.
      
      While at it fix autovacuum_multixact_freeze_max_age to refer to
      multixact.c instead of varsup.c.
      
      Reviewed-By: Robert Haas
      Discussion: CA+TgmoYmQPHcrc3GSs7vwvrbTkbcGD9Gik=OztbDGGrovkkEzQ@mail.gmail.com
      Backpatch: 9.0 (in parts)
      f12932dd
  6. Sep 22, 2015
    • Joe Conway's avatar
      Fix sepgsql regression tests (9.2-only patch). · e90a629e
      Joe Conway authored
      The regression tests for sepgsql were broken by changes in the
      base distro as-shipped policies. Specifically, definition of
      unconfined_t in the system default policy was changed to bypass
      multi-category rules, which the regression test depended on.
      Fix that by defining a custom privileged domain
      (sepgsql_regtest_superuser_t) and using it instead of system's
      unconfined_t domain. The new sepgsql_regtest_superuser_t domain
      performs almost like the current unconfined_t, but restricted by
      multi-category policy as the traditional unconfined_t was.
      
      The custom policy module is a self defined domain, and so should not
      be affected by related future system policy changes. However, it still
      uses the unconfined_u:unconfined_r pair for selinux-user and role.
      Those definitions have not been changed for several years and seem
      less risky to rely on than the unconfined_t domain. Additionally, if
      we define custom user/role, they would need to be manually defined
      at the operating system level, adding more complexity to an already
      non-standard and complex regression test.
      
      Applies only to 9.2. Unlike the previous similar patch, commit 794e2558,
      this also fixes a bug related to processing SELECT INTO statement.
      Because v9.2 didn't have ObjectAccessPostCreate to inform the context
      when a relation is newly created, sepgsql had an alternative method.
      However, related code in sepgsql_object_access() neglected to consider
      T_CreateTableAsStmt, thus no label was assigned on the new relation.
      This logic was removed and replaced starting in 9.3.
      
      Patch by Kohei KaiGai.
      e90a629e
    • Tom Lane's avatar
      Docs: fix typo in to_char() example. · 11b44d1c
      Tom Lane authored
      Per bug #13631 from KOIZUMI Satoru.
      11b44d1c
  7. Sep 21, 2015
    • Tom Lane's avatar
      Fix possible internal overflow in numeric multiplication. · 84448621
      Tom Lane authored
      mul_var() postpones propagating carries until it risks overflow in its
      internal digit array.  However, the logic failed to account for the
      possibility of overflow in the carry propagation step, allowing wrong
      results to be generated in corner cases.  We must slightly reduce the
      when-to-propagate-carries threshold to avoid that.
      
      Discovered and fixed by Dean Rasheed, with small adjustments by me.
      
      This has been wrong since commit d72f6c75,
      so back-patch to all supported branches.
      84448621
    • Noah Misch's avatar
      Restrict file mode creation mask during tmpfile(). · c94b65f6
      Noah Misch authored
      Per Coverity.  Back-patch to 9.0 (all supported versions).
      
      Michael Paquier, reviewed (in earlier versions) by Heikki Linnakangas.
      c94b65f6
  8. Sep 20, 2015
    • Tom Lane's avatar
      Be more wary about partially-valid LOCALLOCK data in RemoveLocalLock(). · ac0c7122
      Tom Lane authored
      RemoveLocalLock() must consider the possibility that LockAcquireExtended()
      failed to palloc the initial space for a locallock's lockOwners array.
      I had evidently meant to cope with this hazard when the code was originally
      written (commit 1785aceb), but missed that
      the pfree needed to be protected with an if-test.  Just to make sure things
      are left in a clean state, reset numLockOwners as well.
      
      Per low-memory testing by Andreas Seltenreich.  Back-patch to all supported
      branches.
      ac0c7122
  9. Sep 19, 2015
  10. Sep 18, 2015
    • Tom Lane's avatar
      Fix low-probability memory leak in regex execution. · dc4e8c10
      Tom Lane authored
      After an internal failure in shortest() or longest() while pinning down the
      exact location of a match, find() forgot to free the DFA structure before
      returning.  This is pretty unlikely to occur, since we just successfully
      ran the "search" variant of the DFA; but it could happen, and it would
      result in a session-lifespan memory leak since this code uses malloc()
      directly.  Problem seems to have been aboriginal in Spencer's library,
      so back-patch all the way.
      
      In passing, correct a thinko in a comment I added awhile back about the
      meaning of the "ntree" field.
      
      I happened across these issues while comparing our code to Tcl's version
      of the library.
      dc4e8c10
  11. Sep 17, 2015
  12. Sep 16, 2015
    • Tom Lane's avatar
      Fix documentation of regular expression character-entry escapes. · 11103c6d
      Tom Lane authored
      The docs claimed that \uhhhh would be interpreted as a Unicode value
      regardless of the database encoding, but it's never been implemented
      that way: \uhhhh and \xhhhh actually mean exactly the same thing, namely
      the character that pg_mb2wchar translates to 0xhhhh.  Moreover we were
      falsely dismissive of the usefulness of Unicode code points above FFFF.
      Fix that.
      
      It's been like this for ages, so back-patch to all supported branches.
      11103c6d
  13. Sep 12, 2015
    • Tom Lane's avatar
      Remove set-but-not-used variable. · 49232d41
      Tom Lane authored
      In branches before 9.3, commit 8703059c caused join_is_legal()'s
      unique_ified variable to become unused, since its only remaining
      use is for LATERAL-related tests which don't exist pre-9.3.
      My compiler didn't complain about that, but Peter's does.
      49232d41
  14. Sep 11, 2015
    • Bruce Momjian's avatar
      pg_dump, pg_upgrade: allow postgres/template1 tablespace moves · befc63e8
      Bruce Momjian authored
      Modify pg_dump to restore postgres/template1 databases to non-default
      tablespaces by switching out of the database to be moved, then switching
      back.
      
      Also, to fix potentially cases where the old/new tablespaces might not
      match, fix pg_upgrade to process new/old tablespaces separately in all
      cases.
      
      Report by Marti Raudsepp
      
      Patch by Marti Raudsepp, me
      
      Backpatch through 9.0
      befc63e8
  15. Sep 10, 2015
    • Tom Lane's avatar
      Fix setrefs.c comment properly. · fe146952
      Tom Lane authored
      The "typo" alleged in commit 1e460d4b was actually a comment that was
      correct when written, but I missed updating it in commit b5282aa8.
      Use a slightly less specific (and hopefully more future-proof) description
      of what is collected.  Back-patch to 9.2 where that commit appeared, and
      revert the comment to its then-entirely-correct state before that.
      fe146952
    • Stephen Frost's avatar
      Fix typo in setrefs.c · f4ea1b35
      Stephen Frost authored
      We're adding OIDs, not TIDs, to invalItems.
      
      Pointed out by Etsuro Fujita.
      
      Back-patch to all supported branches.
      f4ea1b35
    • Tom Lane's avatar
      Fix minor bug in regexp makesearch() function. · 3718015e
      Tom Lane authored
      The list-wrangling here was done wrong, allowing the same state to get
      put into the list twice.  The following loop then would clone it twice.
      The second clone would wind up with no inarcs, so that there was no
      observable misbehavior AFAICT, but a useless state in the finished NFA
      isn't an especially good thing.
      3718015e
  16. Sep 09, 2015
    • Fujii Masao's avatar
      Remove files signaling a standby promotion request at postmaster startup · 67518a14
      Fujii Masao authored
      This commit makes postmaster forcibly remove the files signaling
      a standby promotion request. Otherwise, the existence of those files
      can trigger a promotion too early, whether a user wants that or not.
      
      This removal of files is usually unnecessary because they can exist
      only during a few moments during a standby promotion. However
      there is a race condition: if pg_ctl promote is executed and creates
      the files during a promotion, the files can stay around even after
      the server is brought up to new master. Then, if new standby starts
      by using the backup taken from that master, the files can exist
      at the server startup and should be removed in order to avoid
      an unexpected promotion.
      
      Back-patch to 9.1 where promote signal file was introduced.
      
      Problem reported by Feike Steenbergen.
      Original patch by Michael Paquier, modified by me.
      
      Discussion: 20150528100705.4686.91426@wrigleys.postgresql.org
      67518a14
  17. Sep 08, 2015
  18. Sep 07, 2015
  19. Sep 06, 2015
    • Greg Stark's avatar
      Move DTK_ISODOW DTK_DOW and DTK_DOY to be type UNITS rather than · f4afbe06
      Greg Stark authored
      RESERV. RESERV is meant for tokens like "now" and having them in that
      category throws errors like these when used as an input date:
      
      stark=# SELECT 'doy'::timestamptz;
      ERROR:  unexpected dtype 33 while parsing timestamptz "doy"
      LINE 1: SELECT 'doy'::timestamptz;
                     ^
      stark=# SELECT 'dow'::timestamptz;
      ERROR:  unexpected dtype 32 while parsing timestamptz "dow"
      LINE 1: SELECT 'dow'::timestamptz;
                     ^
      
      Found by LLVM's Libfuzzer
      f4afbe06
  20. Sep 05, 2015
  21. Sep 04, 2015
    • Tom Lane's avatar
      Fix subtransaction cleanup after an outer-subtransaction portal fails. · 39ebb646
      Tom Lane authored
      Formerly, we treated only portals created in the current subtransaction as
      having failed during subtransaction abort.  However, if the error occurred
      while running a portal created in an outer subtransaction (ie, a cursor
      declared before the last savepoint), that has to be considered broken too.
      
      To allow reliable detection of which ones those are, add a bookkeeping
      field to struct Portal that tracks the innermost subtransaction in which
      each portal has actually been executed.  (Without this, we'd end up
      failing portals containing functions that had called the subtransaction,
      thereby breaking plpgsql exception blocks completely.)
      
      In addition, when we fail an outer-subtransaction Portal, transfer its
      resources into the subtransaction's resource owner, so that they're
      released early in cleanup of the subxact.  This fixes a problem reported by
      Jim Nasby in which a function executed in an outer-subtransaction cursor
      could cause an Assert failure or crash by referencing a relation created
      within the inner subtransaction.
      
      The proximate cause of the Assert failure is that AtEOSubXact_RelationCache
      assumed it could blow away a relcache entry without first checking that the
      entry had zero refcount.  That was a bad idea on its own terms, so add such
      a check there, and to the similar coding in AtEOXact_RelationCache.  This
      provides an independent safety measure in case there are still ways to
      provoke the situation despite the Portal-level changes.
      
      This has been broken since subtransactions were invented, so back-patch
      to all supported branches.
      
      Tom Lane and Michael Paquier
      39ebb646
  22. Aug 29, 2015
    • Tom Lane's avatar
      Fix s_lock.h PPC assembly code to be compatible with native AIX assembler. · 472680c5
      Tom Lane authored
      On recent AIX it's necessary to configure gcc to use the native assembler
      (because the GNU assembler hasn't been updated to handle AIX 6+).  This
      caused PG builds to fail with assembler syntax errors, because we'd try
      to compile s_lock.h's gcc asm fragment for PPC, and that assembly code
      relied on GNU-style local labels.  We can't substitute normal labels
      because it would fail in any file containing more than one inlined use of
      tas().  Fortunately, that code is stable enough, and the PPC ISA is simple
      enough, that it doesn't seem like too much of a maintenance burden to just
      hand-code the branch offsets, removing the need for any labels.
      
      Note that the AIX assembler only accepts "$" for the location counter
      pseudo-symbol.  The usual GNU convention is "."; but it appears that all
      versions of gas for PPC also accept "$", so in theory this patch will not
      break any other PPC platforms.
      
      This has been reported by a few people, but Steve Underwood gets the credit
      for being the first to pursue the problem far enough to understand why it
      was failing.  Thanks also to Noah Misch for additional testing.
      472680c5
  23. Aug 27, 2015
  24. Aug 26, 2015
    • Tom Lane's avatar
      Docs: be explicit about datatype matching for lead/lag functions. · 8cffc4f5
      Tom Lane authored
      The default argument, if given, has to be of exactly the same datatype
      as the first argument; but this was not stated in so many words, and
      the error message you get about it might not lead your thought in the
      right direction.  Per bug #13587 from Robert McGehee.
      
      A quick scan says that these are the only two built-in functions with two
      anyelement arguments and no other polymorphic arguments.  There are plenty
      of cases of, eg, anyarray and anyelement, but those seem less likely to
      confuse.  For instance this doesn't seem terribly hard to figure out:
      "function array_remove(integer[], numeric) does not exist".  So I've
      contented myself with fixing these two cases.
      8cffc4f5
  25. Aug 22, 2015
    • Tom Lane's avatar
      Avoid O(N^2) behavior when enlarging SPI tuple table in spi_printtup(). · d951d606
      Tom Lane authored
      For no obvious reason, spi_printtup() was coded to enlarge the tuple
      pointer table by just 256 slots at a time, rather than doubling the size at
      each reallocation, as is our usual habit.  For very large SPI results, this
      makes for O(N^2) time spent in repalloc(), which of course soon comes to
      dominate the runtime.  Use the standard doubling approach instead.
      
      This is a longstanding performance bug, so back-patch to all active
      branches.
      
      Neil Conway
      d951d606
  26. Aug 21, 2015
    • Tom Lane's avatar
      Fix plpython crash when returning string representation of a RECORD result. · dadef8af
      Tom Lane authored
      PLyString_ToComposite() blithely overwrote proc->result.out.d, even though
      for a composite result type the other union variant proc->result.out.r is
      the one that should be valid.  This could result in a crash if out.r had
      in fact been filled in (proc->result.is_rowtype == 1) and then somebody
      later attempted to use that data; as per bug #13579 from Paweł Michalak.
      
      Just to add insult to injury, it didn't work for RECORD results anyway,
      because record_in() would refuse the case.
      
      Fix by doing the I/O function lookup in a local PLyTypeInfo variable,
      as we were doing already in PLyObject_ToComposite().  This is not a great
      technique because any fn_extra data allocated by the input function will
      be leaked permanently (thanks to using TopMemoryContext as fn_mcxt).
      But that's a pre-existing issue that is much less serious than a crash,
      so leave it to be fixed separately.
      
      This bug would be a potential security issue, except that plpython is
      only available to superusers and the crash requires coding the function
      in a way that didn't work before today's patches.
      
      Add regression test cases covering all the supported methods of converting
      composite results.
      
      Back-patch to 9.1 where the faulty coding was introduced.
      dadef8af
Loading