Skip to content
Snippets Groups Projects
  1. Mar 28, 2016
  2. Mar 27, 2016
    • Andres Freund's avatar
      Change various Gin*Is* macros to return 0/1. · 290cc21d
      Andres Freund authored
      Returning the direct result of bit arithmetic, in a macro intended to be
      used in a boolean manner, can be problematic if the return value is
      stored in a variable of type 'bool'. If bool is implemented using C99's
      _Bool, that can lead to comparison failures if the variable is then
      compared again with the expression (see ginStepRight() for an example
      that fails), as _Bool forces the result to be 0/1. That happens in some
      configurations of newer MSVC compilers.  It's also problematic when
      storing the result of such an expression in a narrower type.
      
      Several gin macros have been declared in that style since gin's initial
      commit in 8a3631f8.
      
      There's a lot more macros like this, but this is the only one causing
      regression test failures; and I don't want to commit and backpatch a
      larger patch with lots of conflicts just before the next set of minor
      releases.
      
      Discussion: 20150811154237.GD17575@awork2.anarazel.de
      Backpatch: All supported branches
      290cc21d
  3. Mar 26, 2016
    • Tom Lane's avatar
      Modernize zic's test for valid timezone abbreviations. · 7a68106e
      Tom Lane authored
      We really need to sync all of our IANA-derived timezone code with upstream,
      but that's going to be a large patch and I certainly don't care to shove
      such a thing into stable branches immediately before a release.  As a
      stopgap, copy just the tzcode2016c logic that checks validity of timezone
      abbreviations.  This prevents getting multiple "time zone abbreviation
      differs from POSIX standard" bleats with tzdata 2014b and later.
      7a68106e
    • Tom Lane's avatar
      Update time zone data files to tzdata release 2016c. · 96fa3745
      Tom Lane authored
      DST law changes in Azerbaijan, Chile, Haiti, Palestine, and Russia (Altai,
      Astrakhan, Kirov, Sakhalin, Ulyanovsk regions).  Historical corrections
      for Lithuania, Moldova, Russia (Kaliningrad, Samara, Volgograd).
      
      As of 2015b, the keepers of the IANA timezone database started to use
      numeric time zone abbreviations (e.g., "+04") instead of inventing
      abbreviations not found in the wild like "ASTT".  This causes our rather
      old copy of zic to whine "warning: time zone abbreviation differs from
      POSIX standard" several times during "make install".  This warning is
      harmless according to the IANA folk, and I don't see any problems with
      these abbreviations in some simple tests; but it seems like now would be
      a good time to update our copy of the tzcode stuff.  I'll look into that
      soon.
      96fa3745
  4. Mar 19, 2016
    • Andrew Dunstan's avatar
      Remove dependency on psed for MSVC builds. · 89bf78a9
      Andrew Dunstan authored
      Modern Perl has removed psed from its core distribution, so it might not
      be readily available on some build platforms. We therefore replace its
      use with a Perl script generated by s2p, which is equivalent to the sed
      script. The latter is retained for non-MSVC builds to avoid creating a
      new hard dependency on Perl for non-Windows tarball builds.
      
      Backpatch to all live branches.
      
      Michael Paquier and me.
      89bf78a9
  5. Mar 15, 2016
    • Tom Lane's avatar
      Cope if platform declares mbstowcs_l(), but not locale_t, in <xlocale.h>. · e39f86fe
      Tom Lane authored
      Previously, we included <xlocale.h> only if necessary to get the definition
      of type locale_t.  According to notes in PGAC_TYPE_LOCALE_T, this is
      important because on some versions of glibc that file supplies an
      incompatible declaration of locale_t.  (This info may be obsolete, because
      on my RHEL6 box that seems to be the *only* definition of locale_t; but
      there may still be glibc's in the wild for which it's a live concern.)
      
      It turns out though that on FreeBSD and maybe other BSDen, you can get
      locale_t from stdlib.h or locale.h but mbstowcs_l() and friends only from
      <xlocale.h>.  This was leaving us compiling calls to mbstowcs_l() and
      friends with no visible prototype, which causes a warning and could
      possibly cause actual trouble, since it's not declared to return int.
      
      Hence, adjust the configure checks so that we'll include <xlocale.h>
      either if it's necessary to get type locale_t or if it's necessary to
      get a declaration of mbstowcs_l().
      
      Report and patch by Aleksander Alekseev, somewhat whacked around by me.
      Back-patch to all supported branches, since we have been using
      mbstowcs_l() since 9.1.
      e39f86fe
  6. Mar 14, 2016
    • Tom Lane's avatar
      Add missing NULL terminator to list_SECURITY_LABEL_preposition[]. · 39b3ea71
      Tom Lane authored
      On the machines I tried this on, pressing TAB after SECURITY LABEL led to
      being offered ON and FOR as intended, plus random other keywords (varying
      across machines).  But if you were a bit more unlucky you'd get a crash,
      as reported by nummervet@mail.ru in bug #14019.
      
      Seems to have been an aboriginal error in the SECURITY LABEL patch,
      commit 4d355a83.  Hence, back-patch to all supported versions.
      There's no bug in HEAD, though, thanks to our recent tab-completion
      rewrite.
      39b3ea71
  7. Mar 10, 2016
    • Magnus Hagander's avatar
      Avoid crash on old Windows with AVX2-capable CPU for VS2013 builds · 78b59780
      Magnus Hagander authored
      The Visual Studio 2013 CRT generates invalid code when it makes a 64-bit
      build that is later used on a CPU that supports AVX2 instructions using a
      version of Windows before 7SP1/2008R2SP1.
      
      Detect this combination, and in those cases turn off the generation of
      FMA3, per recommendation from the Visual Studio team.
      
      The bug is actually in the CRT shipping with Visual Studio 2013, but
      Microsoft have stated they're only fixing it in newer major versions.
      The fix is therefor conditioned specifically on being built with this
      version of Visual Studio, and not previous or later versions.
      
      Author: Christian Ullrich
      78b59780
    • 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
    • Andres Freund's avatar
      Introduce durable_rename() and durable_link_or_rename(). · c224d44f
      Andres Freund authored
      Renaming a file using rename(2) is not guaranteed to be durable in face
      of crashes; especially on filesystems like xfs and ext4 when mounted
      with data=writeback. To be certain that a rename() atomically replaces
      the previous file contents in the face of crashes and different
      filesystems, one has to fsync the old filename, rename the file, fsync
      the new filename, fsync the containing directory.  This sequence is not
      generally adhered to currently; which exposes us to data loss risks. To
      avoid having to repeat this arduous sequence, introduce
      durable_rename(), which wraps all that.
      
      Also add durable_link_or_rename(). Several places use link() (with a
      fallback to rename()) to rename a file, trying to avoid replacing the
      target file out of paranoia. Some of those rename sequences need to be
      durable as well. There seems little reason extend several copies of the
      same logic, so centralize the link() callers.
      
      This commit does not yet make use of the new functions; they're used in
      a followup commit.
      
      Author: Michael Paquier, Andres Freund
      Discussion: 56583BDD.9060302@2ndquadrant.com
      Backpatch: All supported branches
      c224d44f
  8. Mar 09, 2016
    • Tom Lane's avatar
      Fix incorrect handling of NULL index entries in indexed ROW() comparisons. · c8e05972
      Tom Lane authored
      An index search using a row comparison such as ROW(a, b) > ROW('x', 'y')
      would stop upon reaching a NULL entry in the "b" column, ignoring the
      fact that there might be non-NULL "b" values associated with later values
      of "a".  This happens because _bt_mark_scankey_required() marks the
      subsidiary scankey for "b" as required, which is just wrong: it's for
      a column after the one with the first inequality key (namely "a"), and
      thus can't be considered a required match.
      
      This bit of brain fade dates back to the very beginnings of our support
      for indexed ROW() comparisons, in 2006.  Kind of astonishing that no one
      came across it before Glen Takahashi, in bug #14010.
      
      Back-patch to all supported versions.
      
      Note: the given test case doesn't actually fail in unpatched 9.1, evidently
      because the fix for bug #6278 (i.e., stopping at nulls in either scan
      direction) is required to make it fail.  I'm sure I could devise a case
      that fails in 9.1 as well, perhaps with something involving making a cursor
      back up; but it doesn't seem worth the trouble.
      c8e05972
  9. Mar 08, 2016
    • Andres Freund's avatar
      plperl: Correctly handle empty arrays in plperl_ref_from_pg_array. · ee06c97e
      Andres Freund authored
      plperl_ref_from_pg_array() didn't consider the case that postgrs arrays
      can have 0 dimensions (when they're empty) and accessed the first
      dimension without a check. Fix that by special casing the empty array
      case.
      
      Author: Alex Hunsaker
      Reported-By: Andres Freund / valgrind / buildfarm animal skink
      Discussion: 20160308063240.usnzg6bsbjrne667@alap3.anarazel.de
      Backpatch: 9.1-
      ee06c97e
  10. Mar 07, 2016
    • Tom Lane's avatar
      Fix backwards test for Windows service-ness in pg_ctl. · 15d43196
      Tom Lane authored
      A thinko in a9676139 caused pg_ctl to get it exactly backwards when
      deciding whether to report problems to the Windows eventlog or to stderr.
      Per bug #14001 from Manuel Mathar, who also identified the fix.
      Like the previous patch, back-patch to all supported branches.
      15d43196
    • Tom Lane's avatar
      Fix not-terribly-safe coding in NIImportOOAffixes() and NIImportAffixes(). · 8894c9f7
      Tom Lane authored
      There were two places in spell.c that supposed that they could search
      for a location in a string produced by lowerstr() and then transpose
      the offset into the original string.  But this fails completely if
      lowerstr() transforms any characters into characters of different byte
      length, as can happen in Turkish UTF8 for instance.
      
      We'd added some comments about this coding in commit 51e78ab4,
      but failed to realize that it was not merely confusing but wrong.
      
      Coverity complained about this code years ago, but in such an opaque
      fashion that nobody understood what it was on about.  I'm not entirely
      sure that this issue *is* what it's on about, actually, but perhaps
      this patch will shut it up -- and in any case the problem is clear.
      
      Back-patch to all supported branches.
      8894c9f7
  11. Mar 04, 2016
    • Robert Haas's avatar
      Fix compile breakage due to 0315dfa8. · 756c0f42
      Robert Haas authored
      I wasn't careful enough when back-patching.
      756c0f42
    • Robert Haas's avatar
      Fix query-based tab completion for multibyte characters. · c658d5a9
      Robert Haas authored
      The existing code confuses the byte length of the string (which is
      relevant when passing it to pg_strncasecmp) with the character length
      of the string (which is relevant when it is used with the SQL substring
      function).  Separate those two concepts.
      
      Report and patch by Kyotaro Horiguchi, reviewed by Thomas Munro and
      reviewed and further revised by me.
      c658d5a9
  12. Mar 01, 2016
    • Tom Lane's avatar
      Improve error message for rejecting RETURNING clauses with dropped columns. · dcba544d
      Tom Lane authored
      This error message was written with only ON SELECT rules in mind, but since
      then we also made RETURNING-clause targetlists go through the same logic.
      This means that you got a rather off-topic error message if you tried to
      add a rule with RETURNING to a table having dropped columns.  Ideally we'd
      just support that, but some preliminary investigation says that it might be
      a significant amount of work.  Seeing that Nicklas Avén's complaint is the
      first one we've gotten about this in the ten years or so that the code's
      been like that, I'm unwilling to put much time into it.  Instead, improve
      the error report by issuing a different message for RETURNING cases, and
      revise the associated comment based on this investigation.
      
      Discussion: 1456176604.17219.9.camel@jordogskog.no
      dcba544d
  13. Feb 29, 2016
    • Alvaro Herrera's avatar
      Fix typos · 36d43f05
      Alvaro Herrera authored
      Author: Amit Langote
      36d43f05
    • Tom Lane's avatar
      Avoid multiple free_struct_lconv() calls on same data. · 47792639
      Tom Lane authored
      A failure partway through PGLC_localeconv() led to a situation where
      the next call would call free_struct_lconv() a second time, leading
      to free() on already-freed strings, typically leading to a core dump.
      Add a flag to remember whether we need to do that.
      
      Per report from Thom Brown.  His example case only provokes the failure
      as far back as 9.4, but nonetheless this code is obviously broken, so
      back-patch to all supported branches.
      47792639
  14. Feb 19, 2016
    • Simon Riggs's avatar
      Correct StartupSUBTRANS for page wraparound · c063d3c4
      Simon Riggs authored
      StartupSUBTRANS() incorrectly handled cases near the max pageid in the subtrans
      data structure, which in some cases could lead to errors in startup for Hot
      Standby.
      This patch wraps the pageids correctly, avoiding any such errors.
      Identified by exhaustive crash testing by Jeff Janes.
      
      Jeff Janes
      c063d3c4
  15. Feb 17, 2016
    • Tom Lane's avatar
      Make plpython cope with funny characters in function names. · 7d48349f
      Tom Lane authored
      A function name that's double-quoted in SQL can contain almost any
      characters, but we were using that name directly as part of the name
      generated for the Python-level function, and Python doesn't like
      anything that isn't pretty much a standard identifier.  To fix,
      replace anything that isn't an ASCII letter or digit with an underscore
      in the generated name.  This doesn't create any risk of duplicate Python
      function names because we were already appending the function OID to
      the generated name to ensure uniqueness.  Per bug #13960 from Jim Nasby.
      
      Patch by Jim Nasby, modified a bit by me.  Back-patch to all
      supported branches.
      7d48349f
  16. Feb 15, 2016
    • Tom Lane's avatar
      Suppress compiler warnings about useless comparison of unsigned to zero. · e781baa6
      Tom Lane authored
      Reportedly, some compilers warn about tests like "c < 0" if c is unsigned,
      and hence complain about the character range checks I added in commit
      3bb3f42f.  This is a bit of a pain since
      the regex library doesn't really want to assume that chr is unsigned.
      However, since any such reconfiguration would involve manual edits of
      regcustom.h anyway, we can put it on the shoulders of whoever wants to
      do that to adjust this new range-checking macro correctly.
      
      Per gripes from Coverity and Andres.
      e781baa6
  17. Feb 11, 2016
    • Noah Misch's avatar
      Accept pg_ctl timeout from the PGCTLTIMEOUT environment variable. · 4421b525
      Noah Misch authored
      Many automated test suites call pg_ctl.  Buildfarm members axolotl,
      hornet, mandrill, shearwater, sungazer and tern have failed when server
      shutdown took longer than the pg_ctl default 60s timeout.  This addition
      permits slow hosts to easily raise the timeout without us editing a
      --timeout argument into every test suite pg_ctl call.  Back-patch to 9.1
      (all supported versions) for the sake of automated testing.
      
      Reviewed by Tom Lane.
      4421b525
    • Tom Lane's avatar
      Avoid use of sscanf() to parse ispell dictionary files. · 64f99a2e
      Tom Lane authored
      It turns out that on FreeBSD-derived platforms (including OS X), the
      *scanf() family of functions is pretty much brain-dead about multibyte
      characters.  In particular it will apply isspace() to individual bytes
      of input even when those bytes are part of a multibyte character, thus
      allowing false recognition of a field-terminating space.
      
      We appear to have little alternative other than instituting a coding
      rule that *scanf() is not to be used if the input string might contain
      multibyte characters.  (There was some discussion of relying on "%ls",
      but that probably just moves the portability problem somewhere else,
      and besides it doesn't fully prevent BSD *scanf() from using isspace().)
      
      This patch is a down payment on that: it gets rid of use of sscanf()
      to parse ispell dictionary files, which are certainly at great risk
      of having a problem.  The code is cleaner this way anyway, though
      a bit longer.
      
      In passing, improve a few comments.
      
      Report and patch by Artur Zakirov, reviewed and somewhat tweaked by me.
      Back-patch to all supported branches.
      64f99a2e
  18. Feb 08, 2016
    • Tom Lane's avatar
      Stamp 9.2.15. · a0606058
      Tom Lane authored
    • Peter Eisentraut's avatar
      Translation updates · 6a10dd08
      Peter Eisentraut authored
      Source-Git-URL: git://git.postgresql.org/git/pgtranslation/messages.git
      Source-Git-Hash: e640b67db0ef2d766eb6b5ec60dc3ba5ed4e2ede
      6a10dd08
    • Tom Lane's avatar
      Fix some regex issues with out-of-range characters and large char ranges. · e93516cf
      Tom Lane authored
      Previously, our regex code defined CHR_MAX as 0xfffffffe, which is a
      bad choice because it is outside the range of type "celt" (int32).
      Characters approaching that limit could lead to infinite loops in logic
      such as "for (c = a; c <= b; c++)" where c is of type celt but the
      range bounds are chr.  Such loops will work safely only if CHR_MAX+1
      is representable in celt, since c must advance to beyond b before the
      loop will exit.
      
      Fortunately, there seems no reason not to restrict CHR_MAX to 0x7ffffffe.
      It's highly unlikely that Unicode will ever assign codes that high, and
      none of our other backend encodings need characters beyond that either.
      
      In addition to modifying the macro, we have to explicitly enforce character
      range restrictions on the values of \u, \U, and \x escape sequences, else
      the limit is trivially bypassed.
      
      Also, the code for expanding case-independent character ranges in bracket
      expressions had a potential integer overflow in its calculation of the
      number of characters it could generate, which could lead to allocating too
      small a character vector and then overwriting memory.  An attacker with the
      ability to supply arbitrary regex patterns could easily cause transient DOS
      via server crashes, and the possibility for privilege escalation has not
      been ruled out.
      
      Quite aside from the integer-overflow problem, the range expansion code was
      unnecessarily inefficient in that it always produced a result consisting of
      individual characters, abandoning the knowledge that we had a range to
      start with.  If the input range is large, this requires excessive memory.
      Change it so that the original range is reported as-is, and then we add on
      any case-equivalent characters that are outside that range.  With this
      approach, we can bound the number of individual characters allowed without
      sacrificing much.  This patch allows at most 100000 individual characters,
      which I believe to be more than the number of case pairs existing in
      Unicode, so that the restriction will never be hit in practice.
      
      It's still possible for range() to take awhile given a large character code
      range, so also add statement-cancel detection to its loop.  The downstream
      function dovec() also lacked cancel detection, and could take a long time
      given a large output from range().
      
      Per fuzz testing by Greg Stark.  Back-patch to all supported branches.
      
      Security: CVE-2016-0773
      e93516cf
  19. Feb 06, 2016
    • Noah Misch's avatar
      Force certain "pljava" custom GUCs to be PGC_SUSET. · de9766d3
      Noah Misch authored
      Future PL/Java versions will close CVE-2016-0766 by making these GUCs
      PGC_SUSET.  This PostgreSQL change independently mitigates that PL/Java
      vulnerability, helping sites that update PostgreSQL more frequently than
      PL/Java.  Back-patch to 9.1 (all supported versions).
      de9766d3
  20. Feb 05, 2016
  21. Feb 04, 2016
    • Tom Lane's avatar
      In pg_dump, ensure that view triggers are processed after view rules. · 4f58a700
      Tom Lane authored
      If a view is split into CREATE TABLE + CREATE RULE to break a circular
      dependency, then any triggers on the view must be dumped/reloaded after
      the CREATE RULE; else the backend may reject the CREATE TRIGGER because
      it's the wrong type of trigger for a plain table.  This works all right
      in plain dump/restore because of pg_dump's sorting heuristic that places
      triggers after rules.  However, when using parallel restore, the ordering
      must be enforced by a dependency --- and we didn't have one.
      
      Fixing this is a mere matter of adding an addObjectDependency() call,
      except that we need to be able to find all the triggers belonging to the
      view relation, and there was no easy way to do that.  Add fields to
      pg_dump's TableInfo struct to remember where the associated TriggerInfo
      struct(s) are.
      
      Per bug report from Dennis Kögel.  The failure can be exhibited at least
      as far back as 9.1, so back-patch to all supported branches.
      4f58a700
  22. Feb 01, 2016
  23. Jan 29, 2016
    • Tom Lane's avatar
      Fix incorrect pattern-match processing in psql's \det command. · a362cc2e
      Tom Lane authored
      listForeignTables' invocation of processSQLNamePattern did not match up
      with the other ones that handle potentially-schema-qualified names; it
      failed to make use of pg_table_is_visible() and also passed the name
      arguments in the wrong order.  Bug seems to have been aboriginal in commit
      0d692a0d.  It accidentally sort of worked as long as you didn't
      inquire too closely into the behavior, although the silliness was later
      exposed by inconsistencies in the test queries added by 59efda3e
      (which I probably should have questioned at the time, but didn't).
      
      Per bug #13899 from Reece Hart.  Patch by Reece Hart and Tom Lane.
      Back-patch to all affected branches.
      a362cc2e
  24. Jan 26, 2016
  25. Jan 20, 2016
  26. Jan 14, 2016
    • Magnus Hagander's avatar
      Properly close token in sspi authentication · df0bd5a0
      Magnus Hagander authored
      We can never leak more than one token, but we shouldn't do that. We
      don't bother closing it in the error paths since the process will
      exit shortly anyway.
      
      Christian Ullrich
      df0bd5a0
    • Tom Lane's avatar
      Handle extension members when first setting object dump flags in pg_dump. · be2b2765
      Tom Lane authored
      pg_dump's original approach to handling extension member objects was to
      run around and clear (or set) their dump flags rather late in its data
      collection process.  Unfortunately, quite a lot of code expects those flags
      to be valid before that; which was an entirely reasonable expectation
      before we added extensions.  In particular, this explains Karsten Hilbert's
      recent report of pg_upgrade failing on a database in which an extension
      has been installed into the pg_catalog schema.  Its objects are initially
      marked as not-to-be-dumped on the strength of their schema, and later we
      change them to must-dump because we're doing a binary upgrade of their
      extension; but we've already skipped essential tasks like making associated
      DO_SHELL_TYPE objects.
      
      To fix, collect extension membership data first, and incorporate it in the
      initial setting of the dump flags, so that those are once again correct
      from the get-go.  This has the undesirable side effect of slightly
      lengthening the time taken before pg_dump acquires table locks, but testing
      suggests that the increase in that window is not very much.
      
      Along the way, get rid of ugly special-case logic for deciding whether
      to dump procedural languages, FDWs, and foreign servers; dump decisions
      for those are now correct up-front, too.
      
      In 9.3 and up, this also fixes erroneous logic about when to dump event
      triggers (basically, they were *always* dumped before).  In 9.5 and up,
      transform objects had that problem too.
      
      Since this problem came in with extensions, back-patch to all supported
      versions.
      be2b2765
  27. Jan 12, 2016
    • Tom Lane's avatar
      Avoid dump/reload problems when using both plpython2 and plpython3. · 3843ba51
      Tom Lane authored
      Commit 80371601 installed a safeguard against loading plpython2
      and plpython3 at the same time, but asserted that both could still be
      used in the same database, just not in the same session.  However, that's
      not actually all that practical because dumping and reloading will fail
      (since both libraries necessarily get loaded into the restoring session).
      pg_upgrade is even worse, because it checks for missing libraries by
      loading every .so library mentioned in the entire installation into one
      session, so that you can have only one across the whole cluster.
      
      We can improve matters by not throwing the error immediately in _PG_init,
      but only when and if we're asked to do something that requires calling
      into libpython.  This ameliorates both of the above situations, since
      while execution of CREATE LANGUAGE, CREATE FUNCTION, etc will result in
      loading plpython, it isn't asked to do anything interesting (at least
      not if check_function_bodies is off, as it will be during a restore).
      
      It's possible that this opens some corner-case holes in which a crash
      could be provoked with sufficient effort.  However, since plpython
      only exists as an untrusted language, any such crash would require
      superuser privileges, making it "don't do that" not a security issue.
      To reduce the hazards in this area, the error is still FATAL when it
      does get thrown.
      
      Per a report from Paul Jones.  Back-patch to 9.2, which is as far back
      as the patch applies without work.  (It could be made to work in 9.1,
      but given the lack of previous complaints, I'm disinclined to expend
      effort so far back.  We've been pretty desultory about support for
      Python 3 in 9.1 anyway.)
      3843ba51
  28. Jan 09, 2016
    • Tom Lane's avatar
      Clean up some lack-of-STRICT issues in the core code, too. · 0e7d084a
      Tom Lane authored
      A scan for missed proisstrict markings in the core code turned up
      these functions:
      
      brin_summarize_new_values
      pg_stat_reset_single_table_counters
      pg_stat_reset_single_function_counters
      pg_create_logical_replication_slot
      pg_create_physical_replication_slot
      pg_drop_replication_slot
      
      The first three of these take OID, so a null argument will normally look
      like a zero to them, resulting in "ERROR: could not open relation with OID
      0" for brin_summarize_new_values, and no action for the pg_stat_reset_XXX
      functions.  The other three will dump core on a null argument, though this
      is mitigated by the fact that they won't do so until after checking that
      the caller is superuser or has rolreplication privilege.
      
      In addition, the pg_logical_slot_get/peek[_binary]_changes family was
      intentionally marked nonstrict, but failed to make nullness checks on all
      the arguments; so again a null-pointer-dereference crash is possible but
      only for superusers and rolreplication users.
      
      Add the missing ARGISNULL checks to the latter functions, and mark the
      former functions as strict in pg_proc.  Make that change in the back
      branches too, even though we can't force initdb there, just so that
      installations initdb'd in future won't have the issue.  Since none of these
      bugs rise to the level of security issues (and indeed the pg_stat_reset_XXX
      functions hardly misbehave at all), it seems sufficient to do this.
      
      In addition, fix some order-of-operations oddities in the slot_get_changes
      family, mostly cosmetic, but not the part that moves the function's last
      few operations into the PG_TRY block.  As it stood, there was significant
      risk for an error to exit without clearing historical information from
      the system caches.
      
      The slot_get_changes bugs go back to 9.4 where that code was introduced.
      Back-patch appropriate subsets of the pg_proc changes into all active
      branches, as well.
      0e7d084a
    • Tom Lane's avatar
      Clean up code for widget_in() and widget_out(). · 1eb2c4bf
      Tom Lane authored
      Given syntactically wrong input, widget_in() could call atof() with an
      indeterminate pointer argument, typically leading to a crash; or if it
      didn't do that, it might return a NULL pointer, which again would lead
      to a crash since old-style C functions aren't supposed to do things
      that way.  Fix that by correcting the off-by-one syntax test and
      throwing a proper error rather than just returning NULL.
      
      Also, since widget_in and widget_out have been marked STRICT for a
      long time, their tests for null inputs are just dead code; remove 'em.
      In the oldest branches, also improve widget_out to use snprintf not
      sprintf, just to be sure.
      
      In passing, get rid of a long-since-useless sprintf into a local buffer
      that nothing further is done with, and make some other minor coding
      style cleanups.
      
      In the intended regression-testing usage of these functions, none of
      this is very significant; but if the regression test database were
      left around in a production installation, these bugs could amount
      to a minor security hazard.
      
      Piotr Stefaniak, Michael Paquier, and Tom Lane
      1eb2c4bf
Loading