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

« back to all changes in this revision

Viewing changes to erts/etc/common/escript.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 2007-2009. All Rights Reserved.
5
 
 * 
 
3
 *
 
4
 * Copyright Ericsson AB 2007-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
/*
151
151
    char relpath[PMAX];
152
152
    char abspath[PMAX];
153
153
 
 
154
    if (strlen(origpath) >= sizeof(relpath))
 
155
        error("Path too long");
 
156
 
154
157
    strcpy(relpath, origpath);
155
158
 
156
159
    if (strstr(relpath, DIRSEPSTR) == NULL) {
180
183
                end = strstr(beg, PATHSEPSTR);
181
184
                if (end != NULL) {
182
185
                    sz = end - beg;
183
 
                    strncpy(dir, beg, sz);
184
 
                    dir[sz] = '\0';
185
186
                } else {
186
187
                    sz = strlen(beg);
187
 
                    strcpy(dir, beg);
188
188
                    look_for_sep = FALSE;
189
189
                }
 
190
                if (sz >= sizeof(dir)) {
 
191
                    beg = end + 1;
 
192
                    continue;
 
193
                }
 
194
                strncpy(dir, beg, sz);
 
195
                dir[sz] = '\0';
190
196
                beg = end + 1;
191
197
 
192
198
#ifdef __WIN32__
193
 
                strcpy(wildcard, dir);
194
 
                strcat(wildcard, DIRSEPSTR);
195
 
                strcat(wildcard, relpath); /* basename */
 
199
                erts_snprintf(wildcard, sizeof(wildcard), "%s" DIRSEPSTR "%s",
 
200
            dir, relpath /* basename */);
196
201
                dir_handle = FindFirstFile(wildcard, &find_data);
197
202
                if (dir_handle == INVALID_HANDLE_VALUE) {
198
203
                    /* Try next directory in path */
199
204
                    continue;
200
205
                } else {
201
206
                    /* Wow we found the executable. */
202
 
                    strcpy(abspath, wildcard);
 
207
                    strcpy(relpath, wildcard);
203
208
                    FindClose(dir_handle);
204
 
                    return strsave(abspath);
 
209
                    look_for_sep = FALSE;
 
210
                    break;
205
211
                }
206
212
#else
207
213
                dp = opendir(dir);
216
222
 
217
223
                        if (strcmp(origpath, dirp->d_name) == 0) {
218
224
                            /* Wow we found the executable. */
219
 
                            strcpy(abspath, dir);
220
 
                            strcat(abspath, DIRSEPSTR);
221
 
                            strcat(abspath, dirp->d_name);
 
225
                            erts_snprintf(relpath, sizeof(relpath), "%s" DIRSEPSTR "%s",
 
226
                                dir, dirp->d_name);
222
227
                            closedir(dp);
223
 
                            return strsave(abspath);
 
228
                            look_for_sep = FALSE;
 
229
                            break;
224
230
                        }
225
231
                    }
226
232
                }
239
245
#else
240
246
        if (!realpath(relpath, abspath)) {
241
247
#endif /* __WIN32__ */
242
 
            /* Cannot determine absolute path to escript. Try the relative.  */
243
 
            return strsave(relpath);
 
248
            /* Cannot determine absolute path to escript. Try the origin.  */
 
249
            return strsave(origpath);
244
250
        } else {
245
251
            return strsave(abspath);
246
252
        }
289
295
                    
290
296
                    /* Find end of arg */
291
297
                    end = beg;
292
 
                    while (end && end[0] != ' ') {
 
298
                    while (end && end < (linebuf+LINEBUFSZ-1) && end[0] != ' ') {
293
299
                        if (end[0] == '\n') {
294
300
                            newline = TRUE;
295
301
                            end[0]= '\0';
333
339
        emulator = get_default_emulator(argv[0]);
334
340
    }
335
341
 
 
342
    if (strlen(emulator) >= PMAX)
 
343
        error("Value of environment variable ESCRIPT_EMULATOR is too large");
 
344
 
336
345
    /*
337
346
     * Allocate the argv vector to be used for arguments to Erlang.
338
347
     * Arrange for starting to pushing information in the middle of
339
348
     * the array, to allow easy addition of commands in the beginning.
340
349
     */
341
350
 
342
 
    eargv_size = argc*4+1000;
 
351
    eargv_size = argc*4+1000+LINEBUFSZ/2;
343
352
    eargv_base = (char **) emalloc(eargv_size*sizeof(char*));
344
353
    eargv = eargv_base;
345
354
    eargc = 0;
373
382
    if (strcmp(basename, "escript") == 0) {
374
383
#endif
375
384
        /*
376
 
         * Push all options (without the hyphen) before the script name.
 
385
         * Locate all options before the script name.
377
386
         */
378
387
        
379
388
        while (argc > 1 && argv[1][0] == '-') {
380
 
            PUSH(argv[1]+1);
381
389
            argc--;
382
390
            argv++;
383
391
            last_opt = argv;
386
394
        if (argc <= 1) {
387
395
            error("Missing filename\n");
388
396
        }
389
 
        strcpy(scriptname, argv[1]);
 
397
        strncpy(scriptname, argv[1], sizeof(scriptname));
 
398
        scriptname[sizeof(scriptname)-1] = '\0';
390
399
        argc--;
391
400
        argv++;
392
401
    } else {
394
403
        int len;
395
404
#endif
396
405
        absname = find_prog(argv[0]);
397
 
        strcpy(scriptname, absname);
 
406
#ifdef __WIN32__
 
407
        len = strlen(absname);
 
408
        if (len >= 4 && _stricmp(absname+len-4, ".exe") == 0) {
 
409
            absname[len-4] = '\0';
 
410
        }
 
411
#endif
 
412
 
 
413
        erts_snprintf(scriptname, sizeof(scriptname), "%s.escript",
 
414
        absname);
398
415
        efree(absname);
399
 
#ifdef __WIN32__
400
 
        len = strlen(scriptname);
401
 
        if (len >= 4 && _stricmp(scriptname+len-4, ".exe") == 0) {
402
 
            scriptname[len-4] = '\0';
403
 
        }
404
 
#endif
405
 
        strcat(scriptname, ".escript");
 
416
 
406
417
    }
407
418
 
408
419
    /*
418
429
    PUSH3("-run", "escript", "start");
419
430
 
420
431
    /*
421
 
     * Push all options (without the hyphen) before the script name.
 
432
     * Push all options before the script name. But omit the leading hyphens.
422
433
     */
423
434
    
424
435
    while (first_opt != last_opt) {
453
464
static void
454
465
push_words(char* src)
455
466
{
456
 
    char sbuf[1024];
 
467
    char sbuf[PMAX];
457
468
    char* dst;
458
469
 
459
470
    dst = sbuf;
500
511
    *(--p) = '\0';
501
512
 
502
513
    if (debug) {
503
 
        printf("Processed commandline:%s\n",buff);
 
514
        printf("Processed command line:%s\n",buff);
504
515
    }
505
516
    return buff;
506
517
}
582
593
    va_list ap;
583
594
    
584
595
    va_start(ap, format);
585
 
    vsprintf(sbuf, format, ap);
 
596
    erts_vsnprintf(sbuf, sizeof(sbuf), format, ap);
586
597
    va_end(ap);
587
598
    fprintf(stderr, "escript: %s\n", sbuf);
588
599
    exit(1);
617
628
    char sbuf[MAXPATHLEN];
618
629
    char* s;
619
630
 
 
631
    if (strlen(progname) >= sizeof(sbuf))
 
632
        return ERL_NAME;
 
633
 
620
634
    strcpy(sbuf, progname);
621
635
    for (s = sbuf+strlen(sbuf); s >= sbuf; s--) {
622
636
        if (IS_DIRSEP(*s)) {