~ubuntu-branches/ubuntu/vivid/postgresql-8.4/vivid

« back to all changes in this revision

Viewing changes to src/backend/utils/adt/network.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-02-25 11:17:15 UTC
  • mfrom: (13.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120225111715-b7tf22u4p8ok7hd9
Tags: 8.4.11-1
* Urgency medium due to security fixes.
* New upstream bug fix/security release:
  - Require execute permission on the trigger function for "CREATE
    TRIGGER".
    This missing check could allow another user to execute a trigger
    function with forged input data, by installing it on a table he
    owns. This is only of significance for trigger functions marked
    SECURITY DEFINER, since otherwise trigger functions run as the
    table owner anyway. (CVE-2012-0866)
  - Remove arbitrary limitation on length of common name in SSL
    certificates.
    Both libpq and the server truncated the common name extracted from
    an SSL certificate at 32 bytes. Normally this would cause nothing
    worse than an unexpected verification failure, but there are some
    rather-implausible scenarios in which it might allow one
    certificate holder to impersonate another. The victim would have to
    have a common name exactly 32 bytes long, and the attacker would
    have to persuade a trusted CA to issue a certificate in which the
    common name has that string as a prefix. Impersonating a server
    would also require some additional exploit to redirect client
    connections. (CVE-2012-0867)
  - Convert newlines to spaces in names written in pg_dump comments.
    pg_dump was incautious about sanitizing object names that are
    emitted within SQL comments in its output script. A name containing
    a newline would at least render the script syntactically incorrect.
    Maliciously crafted object names could present a SQL injection risk
    when the script is reloaded. (CVE-2012-0868)
  - Fix btree index corruption from insertions concurrent with
    vacuuming.
    An index page split caused by an insertion could sometimes cause a
    concurrently-running "VACUUM" to miss removing index entries that
    it should remove. After the corresponding table rows are removed,
    the dangling index entries would cause errors (such as "could not
    read block N in file ...") or worse, silently wrong query results
    after unrelated rows are re-inserted at the now-free table
    locations. This bug has been present since release 8.2, but occurs
    so infrequently that it was not diagnosed until now. If you have
    reason to suspect that it has happened in your database, reindexing
    the affected index will fix things.
  - Update per-column permissions, not only per-table permissions, when
    changing table owner.
    Failure to do this meant that any previously granted column
    permissions were still shown as having been granted by the old
    owner. This meant that neither the new owner nor a superuser could
    revoke the now-untraceable-to-table-owner permissions.
  - Allow non-existent values for some settings in "ALTER USER/DATABASE
    SET".
    Allow default_text_search_config, default_tablespace, and
    temp_tablespaces to be set to names that are not known. This is
    because they might be known in another database where the setting
    is intended to be used, or for the tablespace cases because the
    tablespace might not be created yet. The same issue was previously
    recognized for search_path, and these settings now act like that
    one.
  - Avoid crashing when we have problems deleting table files
    post-commit.
    Dropping a table should lead to deleting the underlying disk files
    only after the transaction commits. In event of failure then (for
    instance, because of wrong file permissions) the code is supposed
    to just emit a warning message and go on, since it's too late to
    abort the transaction. This logic got broken as of release 8.4,
    causing such situations to result in a PANIC and an unrestartable
    database.
  - Track the OID counter correctly during WAL replay, even when it
    wraps around.
    Previously the OID counter would remain stuck at a high value until
    the system exited replay mode. The practical consequences of that
    are usually nil, but there are scenarios wherein a standby server
    that's been promoted to master might take a long time to advance
    the OID counter to a reasonable value once values are needed.
  - Fix regular expression back-references with - attached.
    Rather than enforcing an exact string match, the code would
    effectively accept any string that satisfies the pattern
    sub-expression referenced by the back-reference symbol.
    A similar problem still afflicts back-references that are embedded
    in a larger quantified expression, rather than being the immediate
    subject of the quantifier. This will be addressed in a future
    PostgreSQL release.
  - Fix recently-introduced memory leak in processing of inet/cidr
    values.
  - Fix dangling pointer after "CREATE TABLE AS"/"SELECT INTO" in a
    SQL-language function.
    In most cases this only led to an assertion failure in
    assert-enabled builds, but worse consequences seem possible.
  - Fix I/O-conversion-related memory leaks in plpgsql.
  - Improve pg_dump's handling of inherited table columns.
    pg_dump mishandled situations where a child column has a different
    default expression than its parent column. If the default is
    textually identical to the parent's default, but not actually the
    same (for instance, because of schema search path differences) it
    would not be recognized as different, so that after dump and
    restore the child would be allowed to inherit the parent's default.
    Child columns that are NOT NULL where their parent is not could
    also be restored subtly incorrectly.
  - Fix pg_restore's direct-to-database mode for INSERT-style table
    data.
    Direct-to-database restores from archive files made with
    "--inserts" or "--column-inserts" options fail when using
    pg_restore from a release dated September or December 2011, as a
    result of an oversight in a fix for another problem. The archive
    file itself is not at fault, and text-mode output is okay.
  - Allow AT option in ecpg DEALLOCATE statements.
    The infrastructure to support this has been there for awhile, but
    through an oversight there was still an error check rejecting the
    case.
  - Fix error in "contrib/intarray"'s int[] & int[] operator.
    If the smallest integer the two input arrays have in common is 1,
    and there are smaller values in either array, then 1 would be
    incorrectly omitted from the result.
  - Fix error detection in "contrib/pgcrypto"'s encrypt_iv() and
    decrypt_iv().
    These functions failed to report certain types of invalid-input
    errors, and would instead return random garbage values for
    incorrect input.
  - Fix one-byte buffer overrun in "contrib/test_parser".
    The code would try to read one more byte than it should, which
    would crash in corner cases. Since "contrib/test_parser" is only
    example code, this is not a security issue in itself, but bad
    example code is still bad.
  - Use __sync_lock_test_and_set() for spinlocks on ARM, if available.
    This function replaces our previous use of the SWPB instruction,
    which is deprecated and not available on ARMv6 and later. Reports
    suggest that the old code doesn't fail in an obvious way on recent
    ARM boards, but simply doesn't interlock concurrent accesses,
    leading to bizarre failures in multiprocess operation.
  - Use "-fexcess-precision=standard" option when building with gcc
    versions that accept it.
    This prevents assorted scenarios wherein recent versions of gcc
    will produce creative results.
  - Allow use of threaded Python on FreeBSD.
    Our configure script previously believed that this combination
    wouldn't work; but FreeBSD fixed the problem, so remove that error
    check.
* Drop 04-armel-tas.patch, applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
172
172
Datum
173
173
inet_out(PG_FUNCTION_ARGS)
174
174
{
175
 
        inet       *src = PG_GETARG_INET_P(0);
 
175
        inet       *src = PG_GETARG_INET_PP(0);
176
176
 
177
177
        PG_RETURN_CSTRING(network_out(src, false));
178
178
}
180
180
Datum
181
181
cidr_out(PG_FUNCTION_ARGS)
182
182
{
183
 
        inet       *src = PG_GETARG_INET_P(0);
 
183
        inet       *src = PG_GETARG_INET_PP(0);
184
184
 
185
185
        PG_RETURN_CSTRING(network_out(src, true));
186
186
}
299
299
Datum
300
300
inet_send(PG_FUNCTION_ARGS)
301
301
{
302
 
        inet       *addr = PG_GETARG_INET_P(0);
 
302
        inet       *addr = PG_GETARG_INET_PP(0);
303
303
 
304
304
        PG_RETURN_BYTEA_P(network_send(addr, false));
305
305
}
307
307
Datum
308
308
cidr_send(PG_FUNCTION_ARGS)
309
309
{
310
 
        inet       *addr = PG_GETARG_INET_P(0);
 
310
        inet       *addr = PG_GETARG_INET_PP(0);
311
311
 
312
312
        PG_RETURN_BYTEA_P(network_send(addr, true));
313
313
}
316
316
Datum
317
317
inet_to_cidr(PG_FUNCTION_ARGS)
318
318
{
319
 
        inet       *src = PG_GETARG_INET_P(0);
 
319
        inet       *src = PG_GETARG_INET_PP(0);
320
320
        inet       *dst;
321
321
        int                     bits;
322
322
        int byte;
357
357
Datum
358
358
inet_set_masklen(PG_FUNCTION_ARGS)
359
359
{
360
 
        inet       *src = PG_GETARG_INET_P(0);
 
360
        inet       *src = PG_GETARG_INET_PP(0);
361
361
        int                     bits = PG_GETARG_INT32(1);
362
362
        inet       *dst;
363
363
 
381
381
Datum
382
382
cidr_set_masklen(PG_FUNCTION_ARGS)
383
383
{
384
 
        inet       *src = PG_GETARG_INET_P(0);
 
384
        inet       *src = PG_GETARG_INET_PP(0);
385
385
        int                     bits = PG_GETARG_INT32(1);
386
386
        inet       *dst;
387
387
        int byte;
457
457
Datum
458
458
network_cmp(PG_FUNCTION_ARGS)
459
459
{
460
 
        inet       *a1 = PG_GETARG_INET_P(0);
461
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
460
        inet       *a1 = PG_GETARG_INET_PP(0);
 
461
        inet       *a2 = PG_GETARG_INET_PP(1);
462
462
 
463
463
        PG_RETURN_INT32(network_cmp_internal(a1, a2));
464
464
}
469
469
Datum
470
470
network_lt(PG_FUNCTION_ARGS)
471
471
{
472
 
        inet       *a1 = PG_GETARG_INET_P(0);
473
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
472
        inet       *a1 = PG_GETARG_INET_PP(0);
 
473
        inet       *a2 = PG_GETARG_INET_PP(1);
474
474
 
475
475
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) < 0);
476
476
}
478
478
Datum
479
479
network_le(PG_FUNCTION_ARGS)
480
480
{
481
 
        inet       *a1 = PG_GETARG_INET_P(0);
482
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
481
        inet       *a1 = PG_GETARG_INET_PP(0);
 
482
        inet       *a2 = PG_GETARG_INET_PP(1);
483
483
 
484
484
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) <= 0);
485
485
}
487
487
Datum
488
488
network_eq(PG_FUNCTION_ARGS)
489
489
{
490
 
        inet       *a1 = PG_GETARG_INET_P(0);
491
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
490
        inet       *a1 = PG_GETARG_INET_PP(0);
 
491
        inet       *a2 = PG_GETARG_INET_PP(1);
492
492
 
493
493
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) == 0);
494
494
}
496
496
Datum
497
497
network_ge(PG_FUNCTION_ARGS)
498
498
{
499
 
        inet       *a1 = PG_GETARG_INET_P(0);
500
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
499
        inet       *a1 = PG_GETARG_INET_PP(0);
 
500
        inet       *a2 = PG_GETARG_INET_PP(1);
501
501
 
502
502
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) >= 0);
503
503
}
505
505
Datum
506
506
network_gt(PG_FUNCTION_ARGS)
507
507
{
508
 
        inet       *a1 = PG_GETARG_INET_P(0);
509
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
508
        inet       *a1 = PG_GETARG_INET_PP(0);
 
509
        inet       *a2 = PG_GETARG_INET_PP(1);
510
510
 
511
511
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) > 0);
512
512
}
514
514
Datum
515
515
network_ne(PG_FUNCTION_ARGS)
516
516
{
517
 
        inet       *a1 = PG_GETARG_INET_P(0);
518
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
517
        inet       *a1 = PG_GETARG_INET_PP(0);
 
518
        inet       *a2 = PG_GETARG_INET_PP(1);
519
519
 
520
520
        PG_RETURN_BOOL(network_cmp_internal(a1, a2) != 0);
521
521
}
526
526
Datum
527
527
hashinet(PG_FUNCTION_ARGS)
528
528
{
529
 
        inet       *addr = PG_GETARG_INET_P(0);
 
529
        inet       *addr = PG_GETARG_INET_PP(0);
530
530
        int                     addrsize = ip_addrsize(addr);
531
531
 
532
532
        /* XXX this assumes there are no pad bytes in the data structure */
539
539
Datum
540
540
network_sub(PG_FUNCTION_ARGS)
541
541
{
542
 
        inet       *a1 = PG_GETARG_INET_P(0);
543
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
542
        inet       *a1 = PG_GETARG_INET_PP(0);
 
543
        inet       *a2 = PG_GETARG_INET_PP(1);
544
544
 
545
545
        if (ip_family(a1) == ip_family(a2))
546
546
        {
554
554
Datum
555
555
network_subeq(PG_FUNCTION_ARGS)
556
556
{
557
 
        inet       *a1 = PG_GETARG_INET_P(0);
558
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
557
        inet       *a1 = PG_GETARG_INET_PP(0);
 
558
        inet       *a2 = PG_GETARG_INET_PP(1);
559
559
 
560
560
        if (ip_family(a1) == ip_family(a2))
561
561
        {
569
569
Datum
570
570
network_sup(PG_FUNCTION_ARGS)
571
571
{
572
 
        inet       *a1 = PG_GETARG_INET_P(0);
573
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
572
        inet       *a1 = PG_GETARG_INET_PP(0);
 
573
        inet       *a2 = PG_GETARG_INET_PP(1);
574
574
 
575
575
        if (ip_family(a1) == ip_family(a2))
576
576
        {
584
584
Datum
585
585
network_supeq(PG_FUNCTION_ARGS)
586
586
{
587
 
        inet       *a1 = PG_GETARG_INET_P(0);
588
 
        inet       *a2 = PG_GETARG_INET_P(1);
 
587
        inet       *a1 = PG_GETARG_INET_PP(0);
 
588
        inet       *a2 = PG_GETARG_INET_PP(1);
589
589
 
590
590
        if (ip_family(a1) == ip_family(a2))
591
591
        {
602
602
Datum
603
603
network_host(PG_FUNCTION_ARGS)
604
604
{
605
 
        inet       *ip = PG_GETARG_INET_P(0);
 
605
        inet       *ip = PG_GETARG_INET_PP(0);
606
606
        char       *ptr;
607
607
        char            tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
608
608
 
628
628
Datum
629
629
network_show(PG_FUNCTION_ARGS)
630
630
{
631
 
        inet       *ip = PG_GETARG_INET_P(0);
 
631
        inet       *ip = PG_GETARG_INET_PP(0);
632
632
        int                     len;
633
633
        char            tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
634
634
 
651
651
Datum
652
652
inet_abbrev(PG_FUNCTION_ARGS)
653
653
{
654
 
        inet       *ip = PG_GETARG_INET_P(0);
 
654
        inet       *ip = PG_GETARG_INET_PP(0);
655
655
        char       *dst;
656
656
        char            tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
657
657
 
669
669
Datum
670
670
cidr_abbrev(PG_FUNCTION_ARGS)
671
671
{
672
 
        inet       *ip = PG_GETARG_INET_P(0);
 
672
        inet       *ip = PG_GETARG_INET_PP(0);
673
673
        char       *dst;
674
674
        char            tmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
675
675
 
687
687
Datum
688
688
network_masklen(PG_FUNCTION_ARGS)
689
689
{
690
 
        inet       *ip = PG_GETARG_INET_P(0);
 
690
        inet       *ip = PG_GETARG_INET_PP(0);
691
691
 
692
692
        PG_RETURN_INT32(ip_bits(ip));
693
693
}
695
695
Datum
696
696
network_family(PG_FUNCTION_ARGS)
697
697
{
698
 
        inet       *ip = PG_GETARG_INET_P(0);
 
698
        inet       *ip = PG_GETARG_INET_PP(0);
699
699
 
700
700
        switch (ip_family(ip))
701
701
        {
714
714
Datum
715
715
network_broadcast(PG_FUNCTION_ARGS)
716
716
{
717
 
        inet       *ip = PG_GETARG_INET_P(0);
 
717
        inet       *ip = PG_GETARG_INET_PP(0);
718
718
        inet       *dst;
719
719
        int byte;
720
720
        int                     bits;
763
763
Datum
764
764
network_network(PG_FUNCTION_ARGS)
765
765
{
766
 
        inet       *ip = PG_GETARG_INET_P(0);
 
766
        inet       *ip = PG_GETARG_INET_PP(0);
767
767
        inet       *dst;
768
768
        int byte;
769
769
        int                     bits;
807
807
Datum
808
808
network_netmask(PG_FUNCTION_ARGS)
809
809
{
810
 
        inet       *ip = PG_GETARG_INET_P(0);
 
810
        inet       *ip = PG_GETARG_INET_PP(0);
811
811
        inet       *dst;
812
812
        int byte;
813
813
        int                     bits;
849
849
Datum
850
850
network_hostmask(PG_FUNCTION_ARGS)
851
851
{
852
 
        inet       *ip = PG_GETARG_INET_P(0);
 
852
        inet       *ip = PG_GETARG_INET_PP(0);
853
853
        inet       *dst;
854
854
        int byte;
855
855
        int                     bits;
1218
1218
Datum
1219
1219
inetnot(PG_FUNCTION_ARGS)
1220
1220
{
1221
 
        inet       *ip = PG_GETARG_INET_P(0);
 
1221
        inet       *ip = PG_GETARG_INET_PP(0);
1222
1222
        inet       *dst;
1223
1223
 
1224
1224
        dst = (inet *) palloc0(sizeof(inet));
1243
1243
Datum
1244
1244
inetand(PG_FUNCTION_ARGS)
1245
1245
{
1246
 
        inet       *ip = PG_GETARG_INET_P(0);
1247
 
        inet       *ip2 = PG_GETARG_INET_P(1);
 
1246
        inet       *ip = PG_GETARG_INET_PP(0);
 
1247
        inet       *ip2 = PG_GETARG_INET_PP(1);
1248
1248
        inet       *dst;
1249
1249
 
1250
1250
        dst = (inet *) palloc0(sizeof(inet));
1275
1275
Datum
1276
1276
inetor(PG_FUNCTION_ARGS)
1277
1277
{
1278
 
        inet       *ip = PG_GETARG_INET_P(0);
1279
 
        inet       *ip2 = PG_GETARG_INET_P(1);
 
1278
        inet       *ip = PG_GETARG_INET_PP(0);
 
1279
        inet       *ip2 = PG_GETARG_INET_PP(1);
1280
1280
        inet       *dst;
1281
1281
 
1282
1282
        dst = (inet *) palloc0(sizeof(inet));
1359
1359
Datum
1360
1360
inetpl(PG_FUNCTION_ARGS)
1361
1361
{
1362
 
        inet       *ip = PG_GETARG_INET_P(0);
 
1362
        inet       *ip = PG_GETARG_INET_PP(0);
1363
1363
        int64           addend = PG_GETARG_INT64(1);
1364
1364
 
1365
1365
        PG_RETURN_INET_P(internal_inetpl(ip, addend));
1369
1369
Datum
1370
1370
inetmi_int8(PG_FUNCTION_ARGS)
1371
1371
{
1372
 
        inet       *ip = PG_GETARG_INET_P(0);
 
1372
        inet       *ip = PG_GETARG_INET_PP(0);
1373
1373
        int64           addend = PG_GETARG_INT64(1);
1374
1374
 
1375
1375
        PG_RETURN_INET_P(internal_inetpl(ip, -addend));
1379
1379
Datum
1380
1380
inetmi(PG_FUNCTION_ARGS)
1381
1381
{
1382
 
        inet       *ip = PG_GETARG_INET_P(0);
1383
 
        inet       *ip2 = PG_GETARG_INET_P(1);
 
1382
        inet       *ip = PG_GETARG_INET_PP(0);
 
1383
        inet       *ip2 = PG_GETARG_INET_PP(1);
1384
1384
        int64           res = 0;
1385
1385
 
1386
1386
        if (ip_family(ip) != ip_family(ip2))