Skip to content
Snippets Groups Projects
  1. May 02, 2016
    • 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
  2. Mar 17, 2016
    • Tom Lane's avatar
      Fix "pg_bench -C -M prepared". · be6f9ea2
      Tom Lane authored
      This didn't work because when we dropped and re-established a database
      connection, we did not bother to reset session-specific state such as
      the statements-are-prepared flags.
      
      The st->prepared[] array certainly needs to be flushed, and I cleared a
      couple of other fields as well that couldn't possibly retain meaningful
      state for a new connection.
      
      In passing, fix some bogus comments and strange field order choices.
      
      Per report from Robins Tharakan.
      be6f9ea2
  3. Mar 10, 2016
    • Andres Freund's avatar
      Avoid unlikely data-loss scenarios due to rename() without fsync. · ce8f4291
      Andres Freund authored
      Renaming a file using rename(2) is not guaranteed to be durable in face
      of crashes. Use the previously added durable_rename()/durable_link_or_rename()
      in various places where we previously just renamed files.
      
      Most of the changed call sites are arguably not critical, but it seems
      better to err on the side of too much durability.  The most prominent
      known case where the previously missing fsyncs could cause data loss is
      crashes at the end of a checkpoint. After the actual checkpoint has been
      performed, old WAL files are recycled. When they're filled, their
      contents are fdatasynced, but we did not fsync the containing
      directory. An OS/hardware crash in an unfortunate moment could then end
      up leaving that file with its old name, but new content; WAL replay
      would thus not replay it.
      
      Reported-By: Tomas Vondra
      Author: Michael Paquier, Tomas Vondra, Andres Freund
      Discussion: 56583BDD.9060302@2ndquadrant.com
      Backpatch: All supported branches
      ce8f4291
  4. Mar 08, 2016
  5. Feb 18, 2016
    • Tom Lane's avatar
      Fix multiple bugs in contrib/pgstattuple's pgstatindex() function. · 29f29972
      Tom Lane authored
      Dead or half-dead index leaf pages were incorrectly reported as live, as a
      consequence of a code rearrangement I made (during a moment of severe brain
      fade, evidently) in commit d287818e.
      
      The index metapage was not counted in index_size, causing that result to
      not agree with the actual index size on-disk.
      
      Index root pages were not counted in internal_pages, which is inconsistent
      compared to the case of a root that's also a leaf (one-page index), where
      the root would be counted in leaf_pages.  Aside from that inconsistency,
      this could lead to additional transient discrepancies between the reported
      page counts and index_size, since it's possible for pgstatindex's scan to
      see zero or multiple pages marked as BTP_ROOT, if the root moves due to
      a split during the scan.  With these fixes, index_size will always be
      exactly one page more than the sum of the displayed page counts.
      
      Also, the index_size result was incorrectly documented as being measured in
      pages; it's always been measured in bytes.  (While fixing that, I couldn't
      resist doing some small additional wordsmithing on the pgstattuple docs.)
      
      Including the metapage causes the reported index_size to not be zero for
      an empty index.  To preserve the desired property that the pgstattuple
      regression test results are platform-independent (ie, BLCKSZ configuration
      independent), scale the index_size result in the regression tests.
      
      The documentation issue was reported by Otsuka Kenji, and the inconsistent
      root page counting by Peter Geoghegan; the other problems noted by me.
      Back-patch to all supported branches, because this has been broken for
      a long time.
      29f29972
  6. Feb 16, 2016
    • Alvaro Herrera's avatar
      pgbench: avoid FD_ISSET on an invalid file descriptor · daac5377
      Alvaro Herrera authored
      The original code wasn't careful to test the file descriptor returned by
      PQsocket() for an invalid socket.  If an invalid socket did turn up,
      that would amount to calling FD_ISSET with fd = -1, whereby undefined
      behavior can be invoked.
      
      To fix, test file descriptor for validity and stop further processing if
      that fails.
      
      Problem noticed by Coverity.
      
      There is an existing FD_ISSET callsite that does check for invalid
      sockets beforehand, but the error message reported by it was
      strerror(errno); in testing the aforementioned change, that turns out to
      result in "bad socket: Success" which isn't terribly helpful.  Instead
      use PQerrorMessage() in both places which is more likely to contain an
      useful error message.
      
      Backpatch-through: 9.1.
      daac5377
  7. Feb 03, 2016
  8. Jan 15, 2016
  9. Dec 27, 2015
  10. Nov 24, 2015
  11. Nov 14, 2015
  12. Oct 05, 2015
    • 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
      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
  13. 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
  14. 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
  15. Sep 17, 2015
  16. 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
  17. Sep 08, 2015
  18. Sep 05, 2015
  19. Aug 03, 2015
  20. Aug 02, 2015
    • Heikki Linnakangas's avatar
      Fix output of ISBN-13 numbers beginning with 979. · 56187c6f
      Heikki Linnakangas authored
      An EAN beginning with 979 (but not 9790 - those are ISMN's) are accepted
      as ISBN numbers, but they cannot be represented in the old, 10-digit ISBN
      format. They must be output in the new 13-digit ISBN-13 format. We printed
      out an incorrect value for those.
      
      Also add a regression test, to test this and some other basic functionality
      of the module.
      
      Patch by Fabien Coelho. This fixes bug #13442, reported by B.Z. Backpatch
      to 9.1, where we started to recognize ISBN-13 numbers.
      56187c6f
  21. Jul 09, 2015
    • Noah Misch's avatar
      Replace use of "diff -q". · f7b33003
      Noah Misch authored
      POSIX does not specify the -q option, and many implementations do not
      offer it.  Don't bother changing the MSVC build system, because having
      non-GNU diff on Windows is vanishingly unlikely.  Back-patch to 9.2,
      where this invocation was introduced.
      f7b33003
  22. Jul 07, 2015
    • Tom Lane's avatar
      Fix portability issue in pg_upgrade test script: avoid $PWD. · ebe601c4
      Tom Lane authored
      SUSv2-era shells don't set the PWD variable, though anything more modern
      does.  In the buildfarm environment this could lead to test.sh executing
      with PWD pointing to $HOME or another high-level directory, so that there
      were conflicts between concurrent executions of the test in different
      branch subdirectories.  This appears to be the explanation for recent
      intermittent failures on buildfarm members binturong and dingo (and might
      well have something to do with the buildfarm script's failure to capture
      log files from pg_upgrade tests, too).
      
      To fix, just use `pwd` in place of $PWD.  AFAICS test.sh is the only place
      in our source tree that depended on $PWD.  Back-patch to all versions
      containing this script.
      
      Per buildfarm.  Thanks to Oskari Saarenmaa for diagnosing the problem.
      ebe601c4
  23. May 18, 2015
    • Noah Misch's avatar
      pgcrypto: Report errant decryption as "Wrong key or corrupt data". · 0ba20043
      Noah Misch authored
      This has been the predominant outcome.  When the output of decrypting
      with a wrong key coincidentally resembled an OpenPGP packet header,
      pgcrypto could instead report "Corrupt data", "Not text data" or
      "Unsupported compression algorithm".  The distinct "Corrupt data"
      message added no value.  The latter two error messages misled when the
      decrypted payload also exhibited fundamental integrity problems.  Worse,
      error message variance in other systems has enabled cryptologic attacks;
      see RFC 4880 section "14. Security Considerations".  Whether these
      pgcrypto behaviors are likewise exploitable is unknown.
      
      In passing, document that pgcrypto does not resist side-channel attacks.
      Back-patch to 9.0 (all supported versions).
      
      Security: CVE-2015-3167
      0ba20043
    • Peter Eisentraut's avatar
      Fix typos · a05b8cff
      Peter Eisentraut authored
      a05b8cff
  24. May 16, 2015
    • Bruce Momjian's avatar
      pg_upgrade: force timeline 1 in the new cluster · affc04d1
      Bruce Momjian authored
      Previously, this prevented promoted standby servers from being upgraded
      because of a missing WAL history file.  (Timeline 1 doesn't need a
      history file, and we don't copy WAL files anyway.)
      
      Report by Christian Echerer(?), Alexey Klyukin
      
      Backpatch through 9.0
      affc04d1
    • Bruce Momjian's avatar
      pg_upgrade: only allow template0 to be non-connectable · 2a55e713
      Bruce Momjian authored
      This patch causes pg_upgrade to error out during its check phase if:
      
      (1) template0 is marked connectable
      or
      (2) any other database is marked non-connectable
      
      This is done because, in the first case, pg_upgrade would fail because
      the pg_dumpall --globals restore would fail, and in the second case, the
      database would not be restored, leading to data loss.
      
      Report by Matt Landry (1), Stephen Frost (2)
      
      Backpatch through 9.0
      2a55e713
  25. May 05, 2015
    • Tom Lane's avatar
      Fix incorrect declaration of citext's regexp_matches() functions. · d4070d10
      Tom Lane authored
      These functions should return SETOF TEXT[], like the core functions they
      are wrappers for; but they were incorrectly declared as returning just
      TEXT[].  This mistake had two results: first, if there was no match you got
      a scalar null result, whereas what you should get is an empty set (zero
      rows).  Second, the 'g' flag was effectively ignored, since you would get
      only one result array even if there were multiple matches, as reported by
      Jeff Certain.
      
      While ignoring 'g' is a clear bug, the behavior for no matches might well
      have been thought to be the intended behavior by people who hadn't compared
      it carefully to the core regexp_matches() functions.  So we should tread
      carefully about introducing this change in the back branches.  Still, it
      clearly is a bug and so providing some fix is desirable.
      
      After discussion, the conclusion was to introduce the change in a 1.1
      version of the citext extension (as we would need to do anyway); 1.0 still
      contains the incorrect behavior.  1.1 is the default and only available
      version in HEAD, but it is optional in the back branches, where 1.0 remains
      the default version.  People wishing to adopt the fix in back branches will
      need to explicitly do ALTER EXTENSION citext UPDATE TO '1.1'.  (I also
      provided a downgrade script in the back branches, so people could go back
      to 1.0 if necessary.)
      
      This should be called out as an incompatible change in the 9.5 release
      notes, although we'll also document it in the next set of back-branch
      release notes.  The notes should mention that any views or rules that use
      citext's regexp_matches() functions will need to be dropped before
      upgrading to 1.1, and then recreated again afterwards.
      
      Back-patch to 9.1.  The bug goes all the way back to citext's introduction
      in 8.4, but pre-9.1 there is no extension mechanism with which to manage
      the change.  Given the lack of previous complaints it seems unnecessary to
      change this behavior in 9.0, anyway.
      d4070d10
  26. Apr 07, 2015
    • Tom Lane's avatar
      Fix assorted inconsistent function declarations. · 6a560f5b
      Tom Lane authored
      While gcc doesn't complain if you declare a function "static" and then
      define it not-static, other compilers do; and in any case the code is
      highly misleading this way.  Add the missing "static" keywords to a
      couple of recent patches.  Per buildfarm member pademelon.
      6a560f5b
  27. Mar 30, 2015
    • Andrew Dunstan's avatar
      Run pg_upgrade and pg_resetxlog with restricted token on Windows · 94856631
      Andrew Dunstan authored
      As with initdb these programs need to run with a restricted token, and
      if they don't pg_upgrade will fail when run as a user with Adminstrator
      privileges.
      
      Backpatch to all live branches. On the development branch the code is
      reorganized so that the restricted token code is now in a single
      location. On the stable bramches a less invasive change is made by
      simply copying the relevant code to pg_upgrade.c and pg_resetxlog.c.
      
      Patches and bug report from Muhammad Asif Naeem, reviewed by Michael
      Paquier, slightly edited by me.
      94856631
  28. Mar 16, 2015
    • Tom Lane's avatar
      Replace insertion sort in contrib/intarray with qsort(). · 8582ae7a
      Tom Lane authored
      It's all very well to claim that a simplistic sort is fast in easy
      cases, but O(N^2) in the worst case is not good ... especially if the
      worst case is as easy to hit as "descending order input".  Replace that
      bit with our standard qsort.
      
      Per bug #12866 from Maksym Boguk.  Back-patch to all active branches.
      8582ae7a
  29. Mar 06, 2015
  30. Feb 12, 2015
  31. Feb 02, 2015
    • Noah Misch's avatar
      Cherry-pick security-relevant fixes from upstream imath library. · d1972da8
      Noah Misch authored
      This covers alterations to buffer sizing and zeroing made between imath
      1.3 and imath 1.20.  Valgrind Memcheck identified the buffer overruns
      and reliance on uninitialized data; their exploit potential is unknown.
      Builds specifying --with-openssl are unaffected, because they use the
      OpenSSL BIGNUM facility instead of imath.  Back-patch to 9.0 (all
      supported versions).
      
      Security: CVE-2015-0243
      d1972da8
    • Noah Misch's avatar
      Fix buffer overrun after incomplete read in pullf_read_max(). · d95ebe0a
      Noah Misch authored
      Most callers pass a stack buffer.  The ensuing stack smash can crash the
      server, and we have not ruled out the viability of attacks that lead to
      privilege escalation.  Back-patch to 9.0 (all supported versions).
      
      Marko Tiikkaja
      
      Security: CVE-2015-0243
      d95ebe0a
  32. Jan 30, 2015
    • Tom Lane's avatar
      Fix Coverity warning about contrib/pgcrypto's mdc_finish(). · a97dfdfd
      Tom Lane authored
      Coverity points out that mdc_finish returns a pointer to a local buffer
      (which of course is gone as soon as the function returns), leaving open
      a risk of misbehaviors possibly as bad as a stack overwrite.
      
      In reality, the only possible call site is in process_data_packets()
      which does not examine the returned pointer at all.  So there's no
      live bug, but nonetheless the code is confusing and risky.  Refactor
      to avoid the issue by letting process_data_packets() call mdc_finish()
      directly instead of going through the pullf_read() API.
      
      Although this is only cosmetic, it seems good to back-patch so that
      the logic in pgp-decrypt.c stays in sync across all branches.
      
      Marko Kreen
      a97dfdfd
    • Tom Lane's avatar
      Handle unexpected query results, especially NULLs, safely in connectby(). · 66cc7468
      Tom Lane authored
      connectby() didn't adequately check that the constructed SQL query returns
      what it's expected to; in fact, since commit 08c33c42 it wasn't
      checking that at all.  This could result in a null-pointer-dereference
      crash if the constructed query returns only one column instead of the
      expected two.  Less excitingly, it could also result in surprising data
      conversion failures if the constructed query returned values that were
      not I/O-conversion-compatible with the types specified by the query
      calling connectby().
      
      In all branches, insist that the query return at least two columns;
      this seems like a minimal sanity check that can't break any reasonable
      use-cases.
      
      In HEAD, insist that the constructed query return the types specified by
      the outer query, including checking for typmod incompatibility, which the
      code never did even before it got broken.  This is to hide the fact that
      the implementation does a conversion to text and back; someday we might
      want to improve that.
      
      In back branches, leave that alone, since adding a type check in a minor
      release is more likely to break things than make people happy.  Type
      inconsistencies will continue to work so long as the actual type and
      declared type are I/O representation compatible, and otherwise will fail
      the same way they used to.
      
      Also, in all branches, be on guard for NULL results from the constructed
      query, which formerly would cause null-pointer dereference crashes.
      We now print the row with the NULL but don't recurse down from it.
      
      In passing, get rid of the rather pointless idea that
      build_tuplestore_recursively() should return the same tuplestore that's
      passed to it.
      
      Michael Paquier, adjusted somewhat by me
      66cc7468
  33. Jan 26, 2015
    • Tom Lane's avatar
      Fix volatile-safety issue in dblink's materializeQueryResult(). · 8abd0e2a
      Tom Lane authored
      Some fields of the sinfo struct are modified within PG_TRY and then
      referenced within PG_CATCH, so as with recent patch to async.c, "volatile"
      is necessary for strict POSIX compliance; and that propagates to a couple
      of subroutines as well as materializeQueryResult() itself.  I think the
      risk of actual issues here is probably higher than in async.c, because
      storeQueryResult() is likely to get inlined into materializeQueryResult(),
      leaving the compiler free to conclude that its stores into sinfo fields are
      dead code.
      8abd0e2a
  34. Jan 15, 2015
    • Robert Haas's avatar
      pg_standby: Avoid writing one byte beyond the end of the buffer. · d452bfd1
      Robert Haas authored
      Previously, read() might have returned a length equal to the buffer
      length, and then the subsequent store to buf[len] would write a
      zero-byte one byte past the end.  This doesn't seem likely to be
      a security issue, but there's some chance it could result in
      pg_standby misbehaving.
      
      Spotted by Coverity; patch by Michael Paquier, reviewed by me.
      d452bfd1
Loading