summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
AgeCommit message (Collapse)Author
2007-08-21Fix potential access-off-the-end-of-memory in varbit_out(): it fetched theTom Lane
byte after the last full byte of the bit array, regardless of whether that byte was part of the valid data or not. Found by buildfarm testing. Thanks to Stefan Kaltenbrunner for nailing down the cause.
2007-07-19Make replace(), split_part(), and string_to_array() behave somewhat sanelyTom Lane
when handed an invalidly-encoded pattern. The previous coding could get into an infinite loop if pg_mb2wchar_with_len() returned a zero-length string after we'd tested for nonempty pattern; which is exactly what it will do if the string consists only of an incomplete multibyte character. This led to either an out-of-memory error or a backend crash depending on platform. Per report from Wiktor Wodecki.
2007-06-29Fix a passel of ancient bugs in to_char(), including two distinct bufferTom Lane
overruns (neither of which seem likely to be exploitable as security holes, fortunately, since the provoker can't control the data written). One of these is due to choosing to stomp on the output of a called function, which is bad news in any case; make it treat the called functions' results as read-only. Avoid some unnecessary palloc/pfree traffic too; it's not really helpful to free small temporary objects, and again this is presuming more than it ought to about the nature of the results of called functions. Per report from Patrick Welche and additional code-reading by Imad.
2007-06-02Fix erroneous error reporting for overlength input in text_date(),Tom Lane
text_time(), and text_timetz(). 7.4-vintage bug found by Greg Stark.
2007-01-03Fix regex_fixed_prefix() to cope reasonably well with regex patterns of theTom Lane
form '^(foo)$'. Before, these could never be optimized into indexscans. The recent changes to make psql and pg_dump generate such patterns (for \d commands and -t and related switches, respectively) therefore represented a big performance hit for people with large pg_class catalogs, as seen in recent gripe from Erik Jones. While at it, be more paranoid about case-sensitivity checking in multibyte encodings, and fix some other corner cases in which a regex might be interpreted too liberally.
2006-10-07Fix string_to_array() to correctly handle the case where there areTom Lane
overlapping possible matches for the separator string, such as string_to_array('123xx456xxx789', 'xx'). Also, revise the logic of replace(), split_part(), and string_to_array() to avoid O(N^2) work from redundant searches and conversions to pg_wchar format when there are N matches to the separator string. Backpatched the full patch as far as 8.0. 7.4 also has the bug, but the code has diverged a lot, so I just went for a quick-and-dirty fix of the bug itself in that branch.
2006-05-21Change the backend to reject strings containing invalidly-encoded multibyteTom Lane
characters in all cases. Formerly we mostly just threw warnings for invalid input, and failed to detect it at all if no encoding conversion was required. The tighter check is needed to defend against SQL-injection attacks as per CVE-2006-2313 (further details will be published after release). Embedded zero (null) bytes will be rejected as well. The checks are applied during input to the backend (receipt from client or COPY IN), so it no longer seems necessary to check in textin() and related routines; any string arriving at those functions will already have been validated. Conversion failure reporting (for characters with no equivalent in the destination encoding) has been cleaned up and made consistent while at it. Also, fix a few longstanding errors in little-used encoding conversion routines: win1251_to_iso, win866_to_iso, euc_tw_to_big5, euc_tw_to_mic, mic_to_euc_tw were all broken to varying extents. Patches by Tatsuo Ishii and Tom Lane. Thanks to Akio Ishida and Yasuo Ohgaki for identifying the security issues.
2006-05-21Change \' to '', for SQL standards compliance. Backpatch to 7.3, 7.4,Bruce Momjian
and 8.0. Later releases already patched.
2006-04-13Fix similar_escape() so that SIMILAR TO works properly for patterns involvingTom Lane
alternatives ("|" symbol). The original coding allowed the added ^ and $ constraints to be absorbed into the first and last alternatives, producing a pattern that would match more than it should. Per report from Eric Noriega. I also changed the pattern to add an ARE director ("***:"), ensuring that SIMILAR TO patterns do not change behavior if regex_flavor is changed. This is necessary to make the non-capturing parentheses work, and seems like a good idea on general principles. Back-patched as far as 7.4. 7.3 also has the bug, but a fix seems impractical because that version's regex engine doesn't have non-capturing parens.
2006-01-05Arrange to set the LC_XXX environment variables to match our locale setup.Tom Lane
Back-patch of previous fix in HEAD for plperl-vs-locale issue.
2005-12-22Adjust string comparison so that only bitwise-equal strings are consideredTom Lane
equal: if strcoll claims two strings are equal, check it with strcmp, and sort according to strcmp if not identical. This fixes inconsistent behavior under glibc's hu_HU locale, and probably under some other locales as well. Also, take advantage of the now-well-defined behavior to speed up texteq, textne, bpchareq, bpcharne: they may as well just do a bitwise comparison and not bother with strcoll at all. NOTE: affected databases may need to REINDEX indexes on text columns to be sure they are self-consistent.
2005-12-01Check for overflow in strtol() while parsing datetime inputs.Tom Lane
Michael Fuhr.
2005-08-15array_in() and array_recv() need to be more paranoid about validatingTom Lane
their OID parameter. It was possible to crash the backend with select array_in('{123}',0,0); because that would bypass the needed step of initializing the workspace. These seem to be the only two places with a problem, though (record_in and record_recv don't have the issue, and the other array functions aren't depending on user-supplied input). Back-patch as far as 7.4; 7.3 does not have the bug.
2005-05-26Adjust datetime parsing to be more robust. We now pass the length of theNeil Conway
working buffer into ParseDateTime() and reject too-long input there, rather than checking the length of the input string before calling ParseDateTime(). The old method was bogus because ParseDateTime() can use a variable amount of working space, depending on the content of the input string (e.g. how many fields need to be NUL terminated). This fixes a minor stack overrun -- I don't _think_ it's exploitable, although I won't claim to be an expert. Along the way, fix a bug reported by Mark Dilger: the working buffer allocated by interval_in() was too short, which resulted in rejecting some perfectly valid interval input values. I added a regression test for this fix.
2005-04-30GCC 4.0 includes a new warning option, -Wformat-literal, that emitsNeil Conway
a warning when a variable is used as a format string for printf() and similar functions (if the variable is derived from untrusted data, it could include unexpected formatting sequences). This emits too many warnings to be enabled by default, but it does flag a few dubious constructs in the Postgres tree. This patch fixes up the obvious variants: functions that are passed a variable format string but no additional arguments. Most of these are harmless (e.g. the ruleutils stuff), but there is at least one actual bug here: if you create a trigger named "%sfoo", pg_dump will read uninitialized memory and fail to dump the trigger correctly.
2005-04-23Repair two TIME WITH TIME ZONE bugs found by Dennis Vshivkov. ComparisonTom Lane
of timetz values misbehaved in --enable-integer-datetime cases, and EXTRACT(EPOCH) subtracted the zone instead of adding it in all cases. Backpatch to all supported releases (except --enable-integer-datetime code does not exist in 7.2).
2005-04-20Fix mis-display of negative fractional seconds in interval values forTom Lane
--enable-integer-datetimes case. Per report from Oliver Siegmar.
2005-03-26Prevent to_char(interval) from dumping core on month-related formatsTom Lane
when a zero-month interval is given. Per discussion with Karel.
2005-03-24array_map can't use the fn_extra field of the provided fcinfo struct asTom Lane
its private storage, because that belongs to the function that it is supposed to call. Per report from Ezequiel Tolnay.
2005-01-11interval_out failed to mention 'ago' for negative intervals in SQL andTom Lane
GERMAN datestyles. Ancient bug reported by Terry Lee Tucker.
2004-12-17Make array_cat more paranoid about checking datatypes in empty arrays.Tom Lane
2004-12-17array_map failed to insert correct result type in an empty array.Tom Lane
Per example from Florian Pflug.
2004-12-13Avoid generating excess (and illegal) parentheses around an aliased JOINTom Lane
in prettyprint mode. Andreas Pflug
2004-12-02Teach regex_fixed_prefix() the correct handling of advanced regexTom Lane
escapes --- they aren't simply quoted characters. Problem noted by Antti Salmela. Also fix problem with incorrect handling of multibyte characters when followed by a quantifier.
2004-12-01Fix timestamptz_age() to do calculation in local timezone not GMT, per bug 1332.Tom Lane
2004-11-24Our interface code for Spencer's regexp package was checking for regexpTom Lane
error conditions during regexp compile, but not during regexp execution; any sort of "can't happen" errors would be treated as no-match instead of being reported as they should be. Noticed while trying to duplicate a reported Tcl bug.
2004-10-13Repair possible failure to update hint bits back to disk, perTom Lane
http://archives.postgresql.org/pgsql-hackers/2004-10/msg00464.php. I plan a more permanent fix in HEAD, but for the back branches it seems best to just touch the places that actually have a problem.
2004-10-01Convert pg_stat_get_backend_idset to use the existing SRF support.Tom Lane
This seems the cleanest way of fixing its lack of a shutdown callback, which was preventing it from working correctly in a query that didn't run it to completion. Per bug report from Szima GÄbor.
2004-07-06Fix broken logic for pretty-printing parenthesis-suppression in UNIONTom Lane
et al.
2004-06-13Suppress compile warnings on machines where the INT64CONST() decorationTom Lane
is actually needed. Backport of Oliver Elphick's recent patch.
2004-06-08Add missing check for too-few-inputs when replacing a zero-dimensionalTom Lane
array.
2004-05-31I think I've finally identified the cause of the off-by-one-secondTom Lane
issue in timestamp conversion that we hacked around for so long by ignoring the seconds field from localtime(). It's simple: you have to watch out for platform-specific roundoff error when reducing a possibly-fractional timestamp to integral time_t form. In particular we should subtract off the already-determined fractional fsec field. This should be enough to get an exact answer with int64 timestamps; with float timestamps, throw in a rint() call just to be sure.
2004-05-12Tighten up overflow check in path_recv, pursuant to code review inspiredTom Lane
by Ken Ashcraft's report. I think there is no actual bug here since if the int32 value does wrap a little bit, palloc will still reject it. Still it's better that the code be obviously correct.
2004-05-07NATURAL CROSS JOIN is a contradiction in terms, not to mention disallowedTom Lane
by the SQL spec and by our parser. Thanks to Jonathan Scott for finding this longstanding error.
2004-05-05Don't assume that struct timeval's tv_sec field is the same datatype asTom Lane
time_t; on some platforms they are not the same width. Per Manfred Koizar.
2004-02-27genericcostestimate() neglected to include qual startup cost inTom Lane
indexTotalCost. I think this may not make any real difference in 7.4, but it definitely is a problem with CVS tip's new equation.
2004-02-21Implement a solution to the 'Turkish locale downcases I incorrectly'Tom Lane
problem, per previous discussion. Make some additional changes to centralize the knowledge of just how identifier downcasing is done, in hopes of simplifying any future tweaking in this area.
2004-02-03Ensure that memcmp() does not run off the end of memory, per Kurt Roeckx.Tom Lane
(Same patch committed to HEAD but I fat-fingered the commit message...)
2004-02-02Avoid generating invalid character encoding sequences in make_greater_string.Tom Lane
Not sure how this mistake evaded detection for so long.
2004-01-31Fix text_position to not scan past end of source string in multibyteTom Lane
case, per report from Korea PostgreSQL Users' Group.
2003-12-19Make to_hex() behave portably on negative input values (treat them asTom Lane
unsigned integers). Per report from Jim Crate.
2003-12-17Fix DecodeInterval to handle '-0.1' sanely, per gripe from Tilo Schwarz.Tom Lane
2003-12-07Repair indexed bytea like operations, and related selectivityJoe Conway
functionality. Per bug report by Alvar Freude: http://archives.postgresql.org/pgsql-bugs/2003-12/msg00022.php
2003-12-01netmask() and hostmask() functions should return maximum-length masklen,Tom Lane
per gripe from Joe Sunday.
2003-11-30Make PQescapeBytea and byteaout consistent with each other, andJoe Conway
octal escape all octets outside the range 0x20 to 0x7e. This fixes the problem pointed out by Sergey Yatskevich here: http://archives.postgresql.org/pgsql-bugs/2003-11/msg00140.php
2003-11-16Fix datetime input parsing to accept YYYY-MONTHNAME-DD and related syntaxes,Tom Lane
which had been unintentionally broken by recent changes to tighten up the DateStyle rules for all-numeric date input. Add documentation and regression tests for this, too.
2003-10-31Fix for possible referential integrity violation when a qualified ON INSERTJan Wieck
rule split the query into one INSERT and one UPDATE where the UPDATE then hit's the just created row without modifying the key fields again. In this special case, the new key slipped in totally unchecked. Jan
2003-10-29Fix some corner cases in ACL manipulation: don't foul up on an emptyTom Lane
ACL array, and force languages to be treated as owned by the bootstrap user ID. (pg_language should have a lanowner column, but until it does this will have to do as a workaround.)
2003-10-16Avoid division by zero in estimate_num_groups() when table has no rows.Tom Lane
2003-10-06During ALTER TABLE ADD FOREIGN KEY, try to check the existing rows usingTom Lane
a single LEFT JOIN query instead of firing the check trigger for each row individually. Stephan Szabo, with some kibitzing from Tom Lane and Jan Wieck.