Tweak libpq to avoid crashing due to incorrect buffer size calculation when
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 May 2008 22:02:44 +0000 (22:02 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 29 May 2008 22:02:44 +0000 (22:02 +0000)
commitf90959b9c3f8e84b6c2db591b1bceda7fe43023e
tree5e302d5d9a3dd20a0c6eab32fe8a8b4fdc7617c8
parent05614bd8bd222ea55e04851c566154af83e0738a
Tweak libpq to avoid crashing due to incorrect buffer size calculation when
we are on a 64-bit machine (ie, size_t is wider than int) and someone passes
in a query string that approaches or exceeds INT_MAX bytes.  Also, just for
paranoia's sake, guard against similar overflows in sizing the input buffer.

The backend will not in the foreseeable future be prepared to send or receive
strings exceeding 1GB, so I didn't take the more invasive step of switching
all the buffer index variables from int to size_t; though someday we might
want to do that.

I have a suspicion that this is not the only such bug in libpq, but this
fix is enough to take care of the crash reported by Francisco Reyes.
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-protocol3.c
src/interfaces/libpq/libpq-int.h