Skip to content
Snippets Groups Projects
  1. Jan 09, 2016
    • 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
    • Tom Lane's avatar
      Add STRICT to some C functions created by the regression tests. · 55caeeee
      Tom Lane authored
      These functions readily crash when passed a NULL input value.  The tests
      themselves do not pass NULL values to them; but when the regression
      database is used as a basis for fuzz testing, they cause a lot of noise.
      Also, if someone were to leave a regression database lying about in a
      production installation, these would create a minor security hazard.
      
      Andreas Seltenreich
      55caeeee
  2. Jan 08, 2016
    • Tom Lane's avatar
      Fix unobvious interaction between -X switch and subdirectory creation. · 957e1117
      Tom Lane authored
      Turns out the only reason initdb -X worked is that pg_mkdir_p won't
      whine if you point it at something that's a symlink to a directory.
      Otherwise, the attempt to create pg_xlog/ just like all the other
      subdirectories would have failed.  Let's be a little more explicit
      about what's happening.  Oversight in my patch for bug #13853
      (mea culpa for not testing -X ...)
      957e1117
  3. Jan 07, 2016
    • Tom Lane's avatar
      Use plain mkdir() not pg_mkdir_p() to create subdirectories of PGDATA. · d6d6400c
      Tom Lane authored
      When we're creating subdirectories of PGDATA during initdb, we know darn
      well that the parent directory exists (or should exist) and that the new
      subdirectory doesn't (or shouldn't).  There is therefore no need to use
      anything more complicated than mkdir().  Using pg_mkdir_p() just opens us
      up to unexpected failure modes, such as the one exhibited in bug #13853
      from Nuri Boardman.  It's not very clear why pg_mkdir_p() went wrong there,
      but it is clear that we didn't need to be trying to create parent
      directories in the first place.  We're not even saving any code, as proven
      by the fact that this patch nets out at minus five lines.
      
      Since this is a response to a field bug report, back-patch to all branches.
      d6d6400c
    • Alvaro Herrera's avatar
      Windows: Make pg_ctl reliably detect service status · 5c4cbd5d
      Alvaro Herrera authored
      pg_ctl is using isatty() to verify whether the process is running in a
      terminal, and if not it sends its output to Windows' Event Log ... which
      does the wrong thing when the output has been redirected to a pipe, as
      reported in bug #13592.
      
      To fix, make pg_ctl use the code we already have to detect service-ness:
      in the master branch, move src/backend/port/win32/security.c to src/port
      (with suitable tweaks so that it runs properly in backend and frontend
      environments); pg_ctl already has access to pgport so it Just Works.  In
      older branches, that's likely to cause trouble, so instead duplicate the
      required code in pg_ctl.c.
      
      Author: Michael Paquier
      Bug report and diagnosis: Egon Kocjan
      Backpatch: all supported branches
      5c4cbd5d
  4. Jan 04, 2016
    • Tom Lane's avatar
      Fix treatment of *lpNumberOfBytesRecvd == 0: that's a completion condition. · 9b2eacba
      Tom Lane authored
      pgwin32_recv() has treated a non-error return of zero bytes from WSARecv()
      as being a reason to block ever since the current implementation was
      introduced in commit a4c40f14.  However, so far as one can tell
      from Microsoft's documentation, that is just wrong: what it means is
      graceful connection closure (in stream protocols) or receipt of a
      zero-length message (in message protocols), and neither case should result
      in blocking here.  The only reason the code worked at all was that control
      then fell into the retry loop, which did *not* treat zero bytes specially,
      so we'd get out after only wasting some cycles.  But as of 9.5 we do not
      normally reach the retry loop and so the bug is exposed, as reported by
      Shay Rojansky and diagnosed by Andres Freund.
      
      Remove the unnecessary test on the byte count, and rearrange the code
      in the retry loop so that it looks identical to the initial sequence.
      
      Back-patch of commit 90e61df8.  The
      original plan was to apply this only to 9.5 and up, but after discussion
      and buildfarm testing, it seems better to back-patch.  The noblock code
      path has been at risk of this problem since it was introduced (in 9.0);
      if it did happen in pre-9.5 branches, the symptom would be that a walsender
      would wait indefinitely rather than noticing a loss of connection.  While
      we lack proof that the case has been seen in the field, it seems possible
      that it's happened without being reported.
      9b2eacba
  5. Jan 03, 2016
    • Tom Lane's avatar
      Teach pg_dump to quote reloption values safely. · 1eb515ad
      Tom Lane authored
      Commit c7e27bec fixed this on the backend side, but we neglected
      the fact that several code paths in pg_dump were printing reloptions
      values that had not gotten massaged by ruleutils.  Apply essentially the
      same quoting logic in those places, too.
      1eb515ad
  6. Jan 02, 2016
    • Tom Lane's avatar
      Fix overly-strict assertions in spgtextproc.c. · 5c0d6230
      Tom Lane authored
      spg_text_inner_consistent is capable of reconstructing an empty string
      to pass down to the next index level; this happens if we have an empty
      string coming in, no prefix, and a dummy node label.  (In practice, what
      is needed to trigger that is insertion of a whole bunch of empty-string
      values.)  Then, we will arrive at the next level with in->level == 0
      and a non-NULL (but zero length) in->reconstructedValue, which is valid
      but the Assert tests weren't expecting it.
      
      Per report from Andreas Seltenreich.  This has no impact in non-Assert
      builds, so should not be a problem in production, but back-patch to
      all affected branches anyway.
      
      In passing, remove a couple of useless variable initializations and
      shorten the code by not duplicating DatumGetPointer() calls.
      5c0d6230
    • Tom Lane's avatar
      Adjust back-branch release note description of commits a2a718b2 et al. · c6ab1782
      Tom Lane authored
      As pointed out by Michael Paquier, recovery_min_apply_delay didn't exist
      in 9.0-9.3, making the release note text not very useful.  Instead make it
      talk about recovery_target_xid, which did exist then.
      
      9.0 is already out of support, but we can fix the text in the newer
      branches' copies of its release notes.
      c6ab1782
    • Bruce Momjian's avatar
      Update copyright for 2016 · 25b04756
      Bruce Momjian authored
      Backpatch certain files through 9.1
      25b04756
  7. Jan 01, 2016
    • Tom Lane's avatar
      Teach flatten_reloptions() to quote option values safely. · 69cfe15b
      Tom Lane authored
      flatten_reloptions() supposed that it didn't really need to do anything
      beyond inserting commas between reloption array elements.  However, in
      principle the value of a reloption could be nearly anything, since the
      grammar allows a quoted string there.  Any restrictions on it would come
      from validity checking appropriate to the particular option, if any.
      
      A reloption value that isn't a simple identifier or number could thus lead
      to dump/reload failures due to syntax errors in CREATE statements issued
      by pg_dump.  We've gotten away with not worrying about this so far with
      the core-supported reloptions, but extensions might allow reloption values
      that cause trouble, as in bug #13840 from Kouhei Sutou.
      
      To fix, split the reloption array elements explicitly, and then convert
      any value that doesn't look like a safe identifier to a string literal.
      (The details of the quoting rule could be debated, but this way is safe
      and requires little code.)  While we're at it, also quote reloption names
      if they're not safe identifiers; that may not be a likely problem in the
      field, but we might as well try to be bulletproof here.
      
      It's been like this for a long time, so back-patch to all supported
      branches.
      
      Kouhei Sutou, adjusted some by me
      69cfe15b
    • Tom Lane's avatar
      Add some more defenses against silly estimates to gincostestimate(). · 8e79b24c
      Tom Lane authored
      A report from Andy Colson showed that gincostestimate() was not being
      nearly paranoid enough about whether to believe the statistics it finds in
      the index metapage.  The problem is that the metapage stats (other than the
      pending-pages count) are only updated by VACUUM, and in the worst case
      could still reflect the index's original empty state even when it has grown
      to many entries.  We attempted to deal with that by scaling up the stats to
      match the current index size, but if nEntries is zero then scaling it up
      still gives zero.  Moreover, the proportion of pages that are entry pages
      vs. data pages vs. pending pages is unlikely to be estimated very well by
      scaling if the index is now orders of magnitude larger than before.
      
      We can improve matters by expanding the use of the rule-of-thumb estimates
      I introduced in commit 7fb008c5: if the index has grown by more
      than a cutoff amount (here set at 4X growth) since VACUUM, then use the
      rule-of-thumb numbers instead of scaling.  This might not be exactly right
      but it seems much less likely to produce insane estimates.
      
      I also improved both the scaling estimate and the rule-of-thumb estimate
      to account for numPendingPages, since it's reasonable to expect that that
      is accurate in any case, and certainly pages that are in the pending list
      are not either entry or data pages.
      
      As a somewhat separate issue, adjust the estimation equations that are
      concerned with extra fetches for partial-match searches.  These equations
      suppose that a fraction partialEntries / numEntries of the entry and data
      pages will be visited as a consequence of a partial-match search.  Now,
      it's physically impossible for that fraction to exceed one, but our
      estimate of partialEntries is mostly bunk, and our estimate of numEntries
      isn't exactly gospel either, so we could arrive at a silly value.  In the
      example presented by Andy we were coming out with a value of 100, leading
      to insane cost estimates.  Clamp the fraction to one to avoid that.
      
      Like the previous patch, back-patch to all supported branches; this
      problem can be demonstrated in one form or another in all of them.
      8e79b24c
  8. Dec 28, 2015
    • Tom Lane's avatar
      Document the exponentiation operator as associating left to right. · 7adbde26
      Tom Lane authored
      Common mathematical convention is that exponentiation associates right to
      left.  We aren't going to change the parser for this, but we could note
      it in the operator's description.  (It's already noted in the operator
      precedence/associativity table, but users might not look there.)
      Per bug #13829 from Henrik Pauli.
      7adbde26
    • Alvaro Herrera's avatar
      Fix translation domain in pg_basebackup · 4fb9e610
      Alvaro Herrera authored
      For some reason, we've been overlooking the fact that pg_receivexlog
      and pg_recvlogical are using wrong translation domains all along,
      so their output hasn't ever been translated.  The right domain is
      pg_basebackup, not their own executable names.
      
      Noticed by Ioseph Kim, who's been working on the Korean translation.
      
      Backpatch pg_receivexlog to 9.2 and pg_recvlogical to 9.4.
      4fb9e610
  9. Dec 27, 2015
  10. Dec 21, 2015
    • Alvaro Herrera's avatar
      Rework internals of changing a type's ownership · f9643d0d
      Alvaro Herrera authored
      This is necessary so that REASSIGN OWNED does the right thing with
      composite types, to wit, that it also alters ownership of the type's
      pg_class entry -- previously, the pg_class entry remained owned by the
      original user, which caused later other failures such as the new owner's
      inability to use ALTER TYPE to rename an attribute of the affected
      composite.  Also, if the original owner is later dropped, the pg_class
      entry becomes owned by a non-existant user which is bogus.
      
      To fix, create a new routine AlterTypeOwner_oid which knows whether to
      pass the request to ATExecChangeOwner or deal with it directly, and use
      that in shdepReassignOwner rather than calling AlterTypeOwnerInternal
      directly.  AlterTypeOwnerInternal is now simpler in that it only
      modifies the pg_type entry and recurses to handle a possible array type;
      higher-level tasks are handled by either AlterTypeOwner directly or
      AlterTypeOwner_oid.
      
      I took the opportunity to add a few more objects to the test rig for
      REASSIGN OWNED, so that more cases are exercised.  Additional ones could
      be added for superuser-only-ownable objects (such as FDWs and event
      triggers) but I didn't want to push my luck by adding a new superuser to
      the tests on a backpatchable bug fix.
      
      Per bug #13666 reported by Chris Pacejo.
      
      This is a backpatch of commit 756e7b4c to branches 9.1 -- 9.4.
      f9643d0d
    • Alvaro Herrera's avatar
      some bullshit · 653530c8
      Alvaro Herrera authored
      653530c8
    • Alvaro Herrera's avatar
      adjust ACL owners for REASSIGN and ALTER OWNER TO · 7af3dd54
      Alvaro Herrera authored
      When REASSIGN and ALTER OWNER TO are used, both the object owner and ACL
      list should be changed from the old owner to the new owner. This patch
      fixes types, foreign data wrappers, and foreign servers to change their
      ACL list properly;  they already changed owners properly.
      
      Report by Alexey Bashtanov
      
      This is a backpatch of commit 59367fdf (for bug #9923) by Bruce
      Momjian to branches 9.1 - 9.4; it wasn't backpatched originally out of
      concerns that it would create a backwards compatibility problem, but per
      discussion related to bug #13666 that turns out to have been misguided.
      (Therefore, the entry in the 9.5 release notes should be removed.)
      
      Note that 9.1 didn't have privileges on types (which were introduced by
      commit 72920557), so this commit only changes foreign-data related
      objects in that branch.
      
      Discussion: http://www.postgresql.org/message-id/20151216224004.GL2618@alvherre.pgsql
      	http://www.postgresql.org/message-id/10227.1450373793@sss.pgh.pa.us
      7af3dd54
    • Tom Lane's avatar
      Remove silly completion for "DELETE FROM tabname ...". · 6ecd7f50
      Tom Lane authored
      psql offered USING, WHERE, and SET in this context, but SET is not a valid
      possibility here.  Seems to have been a thinko in commit f5ab0a14
      which added DELETE's USING option.
      6ecd7f50
  11. Dec 17, 2015
    • Tom Lane's avatar
      Fix improper initialization order for readline. · b4177798
      Tom Lane authored
      Turns out we must set rl_basic_word_break_characters *before* we call
      rl_initialize() the first time, because it will quietly copy that value
      elsewhere --- but only on the first call.  (Love these undocumented
      dependencies.)  I broke this yesterday in commit 2ec477dc;
      like that commit, back-patch to all active branches.  Per report from
      Pavel Stehule.
      b4177798
  12. Dec 16, 2015
    • Tom Lane's avatar
      Cope with Readline's failure to track SIGWINCH events outside of input. · bcce4a5e
      Tom Lane authored
      It emerges that libreadline doesn't notice terminal window size change
      events unless they occur while collecting input.  This is easy to stumble
      over if you resize the window while using a pager to look at query output,
      but it can be demonstrated without any pager involvement.  The symptom is
      that queries exceeding one line are misdisplayed during subsequent input
      cycles, because libreadline has the wrong idea of the screen dimensions.
      
      The safest, simplest way to fix this is to call rl_reset_screen_size()
      just before calling readline().  That causes an extra ioctl(TIOCGWINSZ)
      for every command; but since it only happens when reading from a tty, the
      performance impact should be negligible.  A more valid objection is that
      this still leaves a tiny window during entry to readline() wherein delivery
      of SIGWINCH will be missed; but the practical consequences of that are
      probably negligible.  In any case, there doesn't seem to be any good way to
      avoid the race, since readline exposes no functions that seem safe to call
      from a generic signal handler --- rl_reset_screen_size() certainly isn't.
      
      It turns out that we also need an explicit rl_initialize() call, else
      rl_reset_screen_size() dumps core when called before the first readline()
      call.
      
      rl_reset_screen_size() is not present in old versions of libreadline,
      so we need a configure test for that.  (rl_initialize() is present at
      least back to readline 4.0, so we won't bother with a test for it.)
      We would need a configure test anyway since libedit's emulation of
      libreadline doesn't currently include such a function.  Fortunately,
      libedit seems not to have any corresponding bug.
      
      Merlin Moncure, adjusted a bit by me
      bcce4a5e
  13. Dec 14, 2015
    • Alvaro Herrera's avatar
      Add missing CHECK_FOR_INTERRUPTS in lseg_inside_poly · 48a7074a
      Alvaro Herrera authored
      Apparently, there are bugs in this code that cause it to loop endlessly.
      That bug still needs more research, but in the meantime it's clear that
      the loop is missing a check for interrupts so that it can be cancelled
      timely.
      
      Backpatch to 9.1 -- this has been missing since 49475aab.
      48a7074a
    • Heikki Linnakangas's avatar
      Fix out-of-memory error handling in ParameterDescription message processing. · 1e23caae
      Heikki Linnakangas authored
      If libpq ran out of memory while constructing the result set, it would hang,
      waiting for more data from the server, which might never arrive. To fix,
      distinguish between out-of-memory error and not-enough-data cases, and give
      a proper error message back to the client on OOM.
      
      There are still similar issues in handling COPY start messages, but let's
      handle that as a separate patch.
      
      Michael Paquier, Amit Kapila and me. Backpatch to all supported versions.
      1e23caae
    • Andres Freund's avatar
      Correct statement to actually be the intended assert statement. · ea3f30cf
      Andres Freund authored
      e3f4cfc7 introduced a LWLockHeldByMe() call, without the corresponding
      Assert() surrounding it.
      
      Spotted by Coverity.
      
      Backpatch: 9.1+, like the previous commit
      ea3f30cf
    • Tom Lane's avatar
      Docs: document that psql's "\i -" means read from stdin. · 6436445e
      Tom Lane authored
      This has worked that way for a long time, maybe always, but you would
      not have known it from the documentation.  Also back-patch the notes
      I added to HEAD earlier today about behavior of the "-f -" switch,
      which likewise have been valid for many releases.
      6436445e
  14. Dec 13, 2015
  15. Dec 12, 2015
    • Andres Freund's avatar
      Fix ALTER TABLE ... SET TABLESPACE for unlogged relations. · a15ad670
      Andres Freund authored
      Changing the tablespace of an unlogged relation did not WAL log the
      creation and content of the init fork. Thus, after a standby is
      promoted, unlogged relation cannot be accessed anymore, with errors
      like:
      ERROR:  58P01: could not open file "pg_tblspc/...": No such file or directory
      Additionally the init fork was not synced to disk, independent of the
      configured wal_level, a relatively small durability risk.
      
      Investigation of that problem also brought to light that, even for
      permanent relations, the creation of !main forks was not WAL logged,
      i.e. no XLOG_SMGR_CREATE record were emitted. That mostly turns out not
      to be a problem, because these files were created when the actual
      relation data is copied; nonexistent files are not treated as an error
      condition during replay. But that doesn't work for empty files, and
      generally feels a bit haphazard. Luckily, outside init and main forks,
      empty forks don't occur often or are not a problem.
      
      Add the required WAL logging and syncing to disk.
      
      Reported-By: Michael Paquier
      Author: Michael Paquier and Andres Freund
      Discussion: 20151210163230.GA11331@alap3.anarazel.de
      Backpatch: 9.1, where unlogged relations were introduced
      a15ad670
    • Tom Lane's avatar
      Add an expected-file to match behavior of latest libxml2. · f5eebea8
      Tom Lane authored
      Recent releases of libxml2 do not provide error context reports for errors
      detected at the very end of the input string.  This appears to be a bug, or
      at least an infelicity, introduced by the fix for libxml2's CVE-2015-7499.
      We can hope that this behavioral change will get undone before too long;
      but the security patch is likely to spread a lot faster/further than any
      follow-on cleanup, which means this behavior is likely to be present in the
      wild for some time to come.  As a stopgap, add a variant regression test
      expected-file that matches what you get with a libxml2 that acts this way.
      f5eebea8
  16. Dec 11, 2015
    • Alvaro Herrera's avatar
      For REASSIGN OWNED for foreign user mappings · 629842a8
      Alvaro Herrera authored
      As reported in bug #13809 by Alexander Ashurkov, the code for REASSIGN
      OWNED hadn't gotten word about user mappings.  Deal with them in the
      same way default ACLs do, which is to ignore them altogether; they are
      handled just fine by DROP OWNED.  The other foreign object cases are
      already handled correctly by both commands.
      
      Also add a REASSIGN OWNED statement to foreign_data test to exercise the
      foreign data objects.  (The changes are just before the "cleanup" phase,
      so it shouldn't remove any existing live test.)
      
      Reported by Alexander Ashurkov, then independently by Jaime Casanova.
      629842a8
    • Tom Lane's avatar
      Install our "missing" script where PGXS builds can find it. · 98467b35
      Tom Lane authored
      This allows sane behavior in a PGXS build done on a machine where build
      tools such as bison are missing.
      
      Jim Nasby
      98467b35
  17. Dec 10, 2015
    • Andres Freund's avatar
      Fix bug leading to restoring unlogged relations from empty files. · 2de281da
      Andres Freund authored
      At the end of crash recovery, unlogged relations are reset to the empty
      state, using their init fork as the template. The init fork is copied to
      the main fork without going through shared buffers. Unfortunately WAL
      replay so far has not necessarily flushed writes from shared buffers to
      disk at that point. In normal crash recovery, and before the
      introduction of 'fast promotions' in fd4ced52 / 9.3, the
      END_OF_RECOVERY checkpoint flushes the buffers out in time. But with
      fast promotions that's not the case anymore.
      
      To fix, force WAL writes targeting the init fork to be flushed
      immediately (using the new FlushOneBuffer() function). In 9.5+ that
      flush can centrally be triggered from the code dealing with restoring
      full page writes (XLogReadBufferForRedoExtended), in earlier releases
      that responsibility is in the hands of XLOG_HEAP_NEWPAGE's replay
      function.
      
      Backpatch to 9.1, even if this currently is only known to trigger in
      9.3+. Flushing earlier is more robust, and it is advantageous to keep
      the branches similar.
      
      Typical symptoms of this bug are errors like
      'ERROR:  index "..." contains unexpected zero page at block 0'
      shortly after promoting a node.
      
      Reported-By: Thom Brown
      Author: Andres Freund and Michael Paquier
      Discussion: 20150326175024.GJ451@alap3.anarazel.de
      Backpatch: 9.1-
      2de281da
    • Tom Lane's avatar
      Accept flex > 2.5.x on Windows, too. · 7f94a5c1
      Tom Lane authored
      Commit 32f15d05 fixed this in configure, but missed the similar check
      in the MSVC scripts.
      
      Michael Paquier, per report from Victor Wagner
      7f94a5c1
  18. Dec 04, 2015
    • Tom Lane's avatar
      Further improve documentation of the role-dropping process. · 255cc9b2
      Tom Lane authored
      In commit 1ea0c73c I added a section to user-manag.sgml about how to drop
      roles that own objects; but as pointed out by Stephen Frost, I neglected
      that shared objects (databases or tablespaces) may need special treatment.
      Fix that.  Back-patch to supported versions, like the previous patch.
      255cc9b2
  19. Dec 01, 2015
    • Tom Lane's avatar
      Make gincostestimate() cope with hypothetical GIN indexes. · 3d4bdd2f
      Tom Lane authored
      We tried to fetch statistics data from the index metapage, which does not
      work if the index isn't actually present.  If the index is hypothetical,
      instead extrapolate some plausible internal statistics based on the index
      page count provided by the index-advisor plugin.
      
      There was already some code in gincostestimate() to invent internal stats
      in this way, but since it was only meant as a stopgap for pre-9.1 GIN
      indexes that hadn't been vacuumed since upgrading, it was pretty crude.
      If we want it to support index advisors, we should try a little harder.
      A small amount of testing says that it's better to estimate the entry pages
      as 90% of the index, not 100%.  Also, estimating the number of entries
      (keys) as equal to the heap tuple count could be wildly wrong in either
      direction.  Instead, let's estimate 100 entries per entry page.
      
      Perhaps someday somebody will want the index advisor to be able to provide
      these numbers more directly, but for the moment this should serve.
      
      Problem report and initial patch by Julien Rouhaud; modified by me to
      invent less-bogus internal statistics.  Back-patch to all supported
      branches, since we've supported index advisors since 9.0.
      3d4bdd2f
    • Tom Lane's avatar
      Use "g" not "f" format in ecpg's PGTYPESnumeric_from_double(). · 74cf6def
      Tom Lane authored
      The previous coding could overrun the provided buffer size for a very large
      input, or lose precision for a very small input.  Adopt the methodology
      that's been in use in the equivalent backend code for a long time.
      
      Per private report from Bas van Schaik.  Back-patch to all supported
      branches.
      74cf6def
  20. Nov 26, 2015
    • Tom Lane's avatar
      Fix failure to consider failure cases in GetComboCommandId(). · 47e189b5
      Tom Lane authored
      Failure to initially palloc the comboCids array, or to realloc it bigger
      when needed, left combocid's data structures in an inconsistent state that
      would cause trouble if the top transaction continues to execute.  Noted
      while examining a user complaint about the amount of memory used for this.
      (There's not much we can do about that, but it does point up that repalloc
      failure has a non-negligible chance of occurring here.)
      
      In HEAD/9.5, also avoid possible invocation of memcpy() with a null pointer
      in SerializeComboCIDState; cf commit 13bba022.
      47e189b5
  21. Nov 25, 2015
    • Tom Lane's avatar
      Be more paranoid about null return values from libpq status functions. · d44b4dea
      Tom Lane authored
      PQhost() can return NULL in non-error situations, namely when a Unix-socket
      connection has been selected by default.  That behavior is a tad debatable
      perhaps, but for the moment we should make sure that psql copes with it.
      Unfortunately, do_connect() failed to: it could pass a NULL pointer to
      strcmp(), resulting in crashes on most platforms.  This was reported as a
      security issue by ChenQin of Topsec Security Team, but the consensus of
      the security list is that it's just a garden-variety bug with no security
      implications.
      
      For paranoia's sake, I made the keep_password test not trust PQuser or
      PQport either, even though I believe those will never return NULL given
      a valid PGconn.
      
      Back-patch to all supported branches.
      d44b4dea
  22. Nov 24, 2015
  23. Nov 23, 2015
  24. Nov 22, 2015
    • Tom Lane's avatar
      Adopt the GNU convention for handling tar-archive members exceeding 8GB. · b054ca03
      Tom Lane authored
      The POSIX standard for tar headers requires archive member sizes to be
      printed in octal with at most 11 digits, limiting the representable file
      size to 8GB.  However, GNU tar and apparently most other modern tars
      support a convention in which oversized values can be stored in base-256,
      allowing any practical file to be a tar member.  Adopt this convention
      to remove two limitations:
      * pg_dump with -Ft output format failed if the contents of any one table
      exceeded 8GB.
      * pg_basebackup failed if the data directory contained any file exceeding
      8GB.  (This would be a fatal problem for installations configured with a
      table segment size of 8GB or more, and it has also been seen to fail when
      large core dump files exist in the data directory.)
      
      File sizes under 8GB are still printed in octal, so that no compatibility
      issues are created except in cases that would have failed entirely before.
      
      In addition, this patch fixes several bugs in the same area:
      
      * In 9.3 and later, we'd defined tarCreateHeader's file-size argument as
      size_t, which meant that on 32-bit machines it would write a corrupt tar
      header for file sizes between 4GB and 8GB, even though no error was raised.
      This broke both "pg_dump -Ft" and pg_basebackup for such cases.
      
      * pg_restore from a tar archive would fail on tables of size between 4GB
      and 8GB, on machines where either "size_t" or "unsigned long" is 32 bits.
      This happened even with an archive file not affected by the previous bug.
      
      * pg_basebackup would fail if there were files of size between 4GB and 8GB,
      even on 64-bit machines.
      
      * In 9.3 and later, "pg_basebackup -Ft" failed entirely, for any file size,
      on 64-bit big-endian machines.
      
      In view of these potential data-loss bugs, back-patch to all supported
      branches, even though removal of the documented 8GB limit might otherwise
      be considered a new feature rather than a bug fix.
      b054ca03
Loading