~ubuntu-branches/ubuntu/karmic/postgresql-8.4/karmic-security

« back to all changes in this revision

Viewing changes to src/backend/optimizer/util/clauses.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-02-01 22:30:52 UTC
  • mfrom: (0.1.7 upstream) (8.1.3 karmic-proposed)
  • Revision ID: james.westby@ubuntu.com-20110201223052-ikezaq42g6c3yv2e
Tags: 8.4.7-0ubuntu0.9.10
* New upstream security/bug fix release: (LP: #711318)
  - Fix buffer overrun in "contrib/intarray"'s input function for the
    query_int type.
    This bug is a security risk since the function's return address
    could be overwritten. Thanks to Apple Inc's security team for
    reporting this issue and supplying the fix. (CVE-2010-4015)
  - Avoid failures when "EXPLAIN" tries to display a simple-form CASE
    expression.
    If the CASE's test expression was a constant, the planner could
    simplify the CASE into a form that confused the expression-display
    code, resulting in "unexpected CASE WHEN clause" errors.
  - Fix assignment to an array slice that is before the existing range
    of subscripts.
    If there was a gap between the newly added subscripts and the first
    pre-existing subscript, the code miscalculated how many entries
    needed to be copied from the old array's null bitmap, potentially
    leading to data corruption or crash.
  - Avoid unexpected conversion overflow in planner for very distant
    date values.
    The date type supports a wider range of dates than can be
    represented by the timestamp types, but the planner assumed it
    could always convert a date to timestamp with impunity.
  - Fix pg_restore's text output for large objects (BLOBs) when
    standard_conforming_strings is on.
    Although restoring directly to a database worked correctly, string
    escaping was incorrect if pg_restore was asked for SQL text output
    and standard_conforming_strings had been enabled in the source
    database.
  - Fix erroneous parsing of tsquery values containing ... &
    !(subexpression) | ... .
    Queries containing this combination of operators were not executed
    correctly. The same error existed in "contrib/intarray"'s query_int
    type and "contrib/ltree"'s ltxtquery type.
  - Fix bug in "contrib/seg"'s GiST picksplit algorithm.
    This could result in considerable inefficiency, though not actually
    incorrect answers, in a GiST index on a seg column. If you have
    such an index, consider "REINDEX"ing it after installing this
    update. (This is identical to the bug that was fixed in
    "contrib/cube" in the previous update.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2570
2570
                 * placeholder nodes, so that we have the opportunity to reduce
2571
2571
                 * constant test conditions.  For example this allows
2572
2572
                 *              CASE 0 WHEN 0 THEN 1 ELSE 1/0 END
2573
 
                 * to reduce to 1 rather than drawing a divide-by-0 error.
 
2573
                 * to reduce to 1 rather than drawing a divide-by-0 error.  Note
 
2574
                 * that when the test expression is constant, we don't have to
 
2575
                 * include it in the resulting CASE; for example
 
2576
                 *              CASE 0 WHEN x THEN y ELSE z END
 
2577
                 * is transformed by the parser to
 
2578
                 *              CASE 0 WHEN CaseTestExpr = x THEN y ELSE z END
 
2579
                 * which we can simplify to
 
2580
                 *              CASE WHEN 0 = x THEN y ELSE z END
 
2581
                 * It is not necessary for the executor to evaluate the "arg"
 
2582
                 * expression when executing the CASE, since any contained
 
2583
                 * CaseTestExprs that might have referred to it will have been
 
2584
                 * replaced by the constant.
2574
2585
                 *----------
2575
2586
                 */
2576
2587
                CaseExpr   *caseexpr = (CaseExpr *) node;
2589
2600
                /* Set up for contained CaseTestExpr nodes */
2590
2601
                save_case_val = context->case_val;
2591
2602
                if (newarg && IsA(newarg, Const))
 
2603
                {
2592
2604
                        context->case_val = newarg;
 
2605
                        newarg = NULL;          /* not needed anymore, see comment above */
 
2606
                }
2593
2607
                else
2594
2608
                        context->case_val = NULL;
2595
2609
 
2733
2747
                        /*
2734
2748
                         * We can remove null constants from the list. For a non-null
2735
2749
                         * constant, if it has not been preceded by any other
2736
 
                         * non-null-constant expressions then that is the result.
 
2750
                         * non-null-constant expressions then it is the result.  Otherwise,
 
2751
                         * it's the next argument, but we can drop following arguments
 
2752
                         * since they will never be reached.
2737
2753
                         */
2738
2754
                        if (IsA(e, Const))
2739
2755
                        {
2741
2757
                                        continue;       /* drop null constant */
2742
2758
                                if (newargs == NIL)
2743
2759
                                        return e;       /* first expr */
 
2760
                                newargs = lappend(newargs, e);
 
2761
                                break;
2744
2762
                        }
2745
2763
                        newargs = lappend(newargs, e);
2746
2764
                }
3489
3507
 * We must also beware of changing the volatility or strictness status of
3490
3508
 * functions by inlining them.
3491
3509
 *
 
3510
 * Also, at the moment we can't inline functions returning RECORD.  This
 
3511
 * doesn't work in the general case because it discards information such
 
3512
 * as OUT-parameter declarations.
 
3513
 *
3492
3514
 * Returns a simplified expression if successful, or NULL if cannot
3493
3515
 * simplify the function.
3494
3516
 */
3521
3543
        if (funcform->prolang != SQLlanguageId ||
3522
3544
                funcform->prosecdef ||
3523
3545
                funcform->proretset ||
 
3546
                funcform->prorettype == RECORDOID ||
3524
3547
                !heap_attisnull(func_tuple, Anum_pg_proc_proconfig) ||
3525
3548
                funcform->pronargs != list_length(args))
3526
3549
                return NULL;