~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_bif_port.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * %CopyrightBegin%
3
 
 * 
4
 
 * Copyright Ericsson AB 2001-2009. All Rights Reserved.
5
 
 * 
 
3
 *
 
4
 * Copyright Ericsson AB 2001-2010. All Rights Reserved.
 
5
 *
6
6
 * The contents of this file are subject to the Erlang Public License,
7
7
 * Version 1.1, (the "License"); you may not use this file except in
8
8
 * compliance with the License. You should have received a copy of the
9
9
 * Erlang Public License along with this software. If not, it can be
10
10
 * retrieved online at http://www.erlang.org/.
11
 
 * 
 
11
 *
12
12
 * Software distributed under the License is distributed on an "AS IS"
13
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
 * the License for the specific language governing rights and limitations
15
15
 * under the License.
16
 
 * 
 
16
 *
17
17
 * %CopyrightEnd%
18
18
 */
19
19
 
21
21
#  include "config.h"
22
22
#endif
23
23
 
24
 
#ifdef _OSE_
25
 
#  include "ose.h"
26
 
#endif
27
 
 
28
24
#include <ctype.h>
29
25
 
30
26
#define ERTS_WANT_EXTERNAL_TAGS
583
579
    if (prt->bp == NULL) {      /* MUST be CONST! */
584
580
        res = prt->data;
585
581
    } else {
586
 
        Eterm* hp = HAlloc(BIF_P, prt->bp->size);
587
 
        res = copy_struct(prt->data, prt->bp->size, &hp, &MSO(BIF_P));
 
582
        Eterm* hp = HAlloc(BIF_P, prt->bp->used_size);
 
583
        res = copy_struct(prt->data, prt->bp->used_size, &hp, &MSO(BIF_P));
588
584
    }
589
585
    erts_smp_port_unlock(prt);
590
586
    BIF_RET(res);
614
610
    int binary_io;
615
611
    int soft_eof;
616
612
    Sint linebuf;
 
613
    Eterm edir = NIL;
617
614
    byte dir[MAXPATHLEN];
618
615
 
619
616
    /* These are the defaults */
690
687
 
691
688
                } else if (option == am_arg0) {
692
689
                    char *a0;
693
 
                    int n;
694
 
                    if (is_nil(*tp)) {
695
 
                        n = 0;
696
 
                    } else if( (n = is_string(*tp)) == 0) {
 
690
 
 
691
                    if ((a0 = erts_convert_filename_to_native(*tp, ERTS_ALC_T_TMP, 1)) == NULL) {
697
692
                        goto badarg;
698
693
                    }
699
 
                    a0 = (char *) erts_alloc(ERTS_ALC_T_TMP, 
700
 
                                            (n + 1) * sizeof(byte));
701
 
                    if (intlist_to_buf(*tp, a0, n) != n) {
702
 
                        erl_exit(1, "%s:%d: Internal error\n",
703
 
                                 __FILE__, __LINE__);
704
 
                    }
705
 
                    a0[n] = '\0';                   
706
694
                    if (opts.argv == NULL) {
707
695
                        opts.argv = erts_alloc(ERTS_ALC_T_TMP, 
708
696
                                               2 * sizeof(char **));
715
703
                        opts.argv[0] = a0;
716
704
                    }
717
705
                } else if (option == am_cd) {
718
 
                    Eterm iolist;
719
 
                    Eterm heap[4];
720
 
                    int r;
721
 
 
722
 
                    heap[0] = *tp;
723
 
                    heap[1] = make_list(heap+2);
724
 
                    heap[2] = make_small(0);
725
 
                    heap[3] = NIL;
726
 
                    iolist = make_list(heap);
727
 
                    r = io_list_to_buf(iolist, (char*) dir, MAXPATHLEN);
728
 
                    if (r < 0) {
729
 
                        goto badarg;
730
 
                    }
731
 
                    opts.wd = (char *) dir;
 
706
                    edir = *tp;
732
707
                } else {
733
708
                    goto badarg;
734
709
                }
840
815
                goto badarg;
841
816
            }
842
817
            name = tp[1];
843
 
            if (is_atom(name)) {
844
 
                name_buf = (char *) erts_alloc(ERTS_ALC_T_TMP,
845
 
                                               atom_tab(atom_val(name))->len+1);
846
 
                sys_memcpy((void *) name_buf,
847
 
                           (void *) atom_tab(atom_val(name))->name, 
848
 
                           atom_tab(atom_val(name))->len);
849
 
                name_buf[atom_tab(atom_val(name))->len] = '\0';
850
 
            } else if ((i = is_string(name))) {
851
 
                name_buf = (char *) erts_alloc(ERTS_ALC_T_TMP, i + 1);
852
 
                if (intlist_to_buf(name, name_buf, i) != i)
853
 
                    erl_exit(1, "%s:%d: Internal error\n", __FILE__, __LINE__);
854
 
                name_buf[i] = '\0';
855
 
            } else {
 
818
            if ((name_buf = erts_convert_filename_to_native(name,ERTS_ALC_T_TMP,0)) == NULL) {
856
819
                goto badarg;
857
820
            }
858
821
            opts.spawn_type = ERTS_SPAWN_EXECUTABLE;
894
857
        /* Argument vector only if explicit spawn_executable */
895
858
        goto badarg;
896
859
    }
897
 
        
 
860
 
 
861
    if (edir != NIL) {
 
862
        /* A working directory is expressed differently if spawn_executable, i.e. Unicode is handles 
 
863
           for spawn_executable... */
 
864
        if (opts.spawn_type != ERTS_SPAWN_EXECUTABLE) {
 
865
            Eterm iolist;
 
866
            DeclareTmpHeap(heap,4,p);
 
867
            int r;
 
868
            
 
869
            UseTmpHeap(4,p);
 
870
            heap[0] = edir;
 
871
            heap[1] = make_list(heap+2);
 
872
            heap[2] = make_small(0);
 
873
            heap[3] = NIL;
 
874
            iolist = make_list(heap);
 
875
            r = io_list_to_buf(iolist, (char*) dir, MAXPATHLEN);
 
876
            UnUseTmpHeap(4,p);
 
877
            if (r < 0) {
 
878
                goto badarg;
 
879
            }
 
880
            opts.wd = (char *) dir;
 
881
        } else {
 
882
            if ((opts.wd = erts_convert_filename_to_native(edir,ERTS_ALC_T_TMP,0)) == NULL) {
 
883
                goto badarg;
 
884
            }
 
885
        }
 
886
    }
898
887
 
899
888
    if (driver != &spawn_driver && opts.exit_status) {
900
889
        goto badarg;
943
932
    if (opts.argv) {
944
933
        free_args(opts.argv);
945
934
    }
 
935
    if (opts.wd && opts.wd != ((char *)dir)) {
 
936
        erts_free(ERTS_ALC_T_TMP, (void *) opts.wd);
 
937
    }
946
938
    return port_num;
947
939
    
948
940
 badarg:
952
944
#undef OPEN_PORT_ERROR
953
945
}
954
946
 
 
947
/* Arguments can be given i unicode and as raw binaries, convert filename is used to convert */
955
948
static char **convert_args(Eterm l)
956
949
{
957
950
    char **pp;
968
961
    pp[i++] = erts_default_arg0;
969
962
    while (is_list(l)) {
970
963
        str = CAR(list_val(l));
971
 
 
972
 
        if (is_nil(str)) {
973
 
            n = 0;
974
 
        } else if( (n = is_string(str)) == 0) {
975
 
            /* Not a string... */
 
964
        if ((b = erts_convert_filename_to_native(str,ERTS_ALC_T_TMP,1)) == NULL) {
976
965
            int j;
977
966
            for (j = 1; j < i; ++j)
978
967
                erts_free(ERTS_ALC_T_TMP, pp[j]);
979
968
            erts_free(ERTS_ALC_T_TMP, pp);
980
969
            return NULL;
981
 
        }
982
 
        b = (char *) erts_alloc(ERTS_ALC_T_TMP, (n + 1) * sizeof(byte));
983
 
        pp[i++] = (char *) b;
984
 
        if (intlist_to_buf(str, b, n) != n)
985
 
            erl_exit(1, "%s:%d: Internal error\n", __FILE__, __LINE__);
986
 
        b[n] = '\0';
 
970
        }           
 
971
        pp[i++] = b;
987
972
        l = CDR(list_val(l));
988
973
    }
989
974
    pp[i] = NULL;
1077
1062
    Eterm res;   /* Out */
1078
1063
    int string_as_bin; /* return strings as binaries (http_bin): */
1079
1064
    byte* aligned_ptr;
 
1065
    Uint bin_sz;
1080
1066
    Eterm orig;
1081
1067
    Uint bin_offs;
1082
1068
    byte bin_bitoffs;
1083
1069
};
1084
1070
 
 
1071
#define in_area(ptr,start,nbytes) \
 
1072
    ((unsigned long)((char*)(ptr) - (char*)(start)) < (nbytes))
 
1073
 
1085
1074
static Eterm
1086
1075
http_bld_string(struct packet_callback_args* pca, Uint **hpp, Uint *szp,
1087
1076
                const char *str, Sint len)
1088
1077
{
1089
1078
    Eterm res = THE_NON_VALUE;
1090
1079
    Uint size;
 
1080
    int make_subbin;
1091
1081
 
1092
1082
    if (pca->string_as_bin) {
1093
1083
        size = heap_bin_size(len);
1094
 
    
 
1084
        make_subbin = (size > ERL_SUB_BIN_SIZE
 
1085
                       && in_area(str, pca->aligned_ptr, pca->bin_sz));
1095
1086
        if (szp) {
1096
 
            *szp += (size > ERL_SUB_BIN_SIZE) ? ERL_SUB_BIN_SIZE : size;        
 
1087
            *szp += make_subbin ? ERL_SUB_BIN_SIZE : size;
1097
1088
        }
1098
1089
        if (hpp) {
1099
1090
            res = make_binary(*hpp);
1100
 
            if (size > ERL_SUB_BIN_SIZE) {
 
1091
            if (make_subbin) {
1101
1092
                ErlSubBin* bin = (ErlSubBin*) *hpp;
1102
1093
                bin->thing_word = HEADER_SUB_BIN;
1103
1094
                bin->size = len;
1328
1319
    int packet_sz;           /*-------Binaries involved: ------------------*/
1329
1320
    byte* bin_ptr;           /*| orig: original binary                     */
1330
1321
    byte bin_bitsz;          /*| bin: BIF_ARG_2, may be sub-binary of orig */
1331
 
    Uint bin_sz;             /*| packet: prefix of bin                     */
 
1322
                             /*| packet: prefix of bin                     */
1332
1323
    char* body_ptr;          /*| body: part of packet to return            */
1333
1324
    int body_sz;             /*| rest: bin without packet                  */
1334
1325
    struct packet_callback_args pca;
1389
1380
    }
1390
1381
 
1391
1382
 
1392
 
    bin_sz = binary_size(BIF_ARG_2);
 
1383
    pca.bin_sz = binary_size(BIF_ARG_2);
1393
1384
    ERTS_GET_BINARY_BYTES(BIF_ARG_2, bin_ptr, pca.bin_bitoffs, bin_bitsz);  
1394
1385
    if (pca.bin_bitoffs != 0) {
1395
 
        pca.aligned_ptr = erts_alloc(ERTS_ALC_T_TMP, bin_sz);
1396
 
        erts_copy_bits(bin_ptr, pca.bin_bitoffs, 1, pca.aligned_ptr, 0, 1, bin_sz*8);
 
1386
        pca.aligned_ptr = erts_alloc(ERTS_ALC_T_TMP, pca.bin_sz);
 
1387
        erts_copy_bits(bin_ptr, pca.bin_bitoffs, 1, pca.aligned_ptr, 0, 1, pca.bin_sz*8);
1397
1388
    }
1398
1389
    else {
1399
1390
        pca.aligned_ptr = bin_ptr;
1400
1391
    }
1401
 
    packet_sz = packet_get_length(type, (char*)pca.aligned_ptr, bin_sz,
 
1392
    packet_sz = packet_get_length(type, (char*)pca.aligned_ptr, pca.bin_sz,
1402
1393
                                  max_plen, trunc_len, &http_state);
1403
 
    if (!(packet_sz > 0 && packet_sz <= bin_sz)) {
 
1394
    if (!(packet_sz > 0 && packet_sz <= pca.bin_sz)) {
1404
1395
        if (packet_sz < 0) {
1405
1396
            goto error;
1406
1397
        }
1456
1447
 
1457
1448
    rest = (ErlSubBin *) hp;
1458
1449
    rest->thing_word = HEADER_SUB_BIN;
1459
 
    rest->size = bin_sz - packet_sz;
 
1450
    rest->size = pca.bin_sz - packet_sz;
1460
1451
    rest->offs = pca.bin_offs + packet_sz;
1461
1452
    rest->orig = pca.orig;
1462
1453
    rest->bitoffs = pca.bin_bitoffs;