Subversion Repositories SvarDOS

Rev

Rev 543 | Rev 571 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 543 Rev 548
Line 61... Line 61...
61
/* checks for valguards at specific memory locations, returns 0 on success */
61
/* checks for valguards at specific memory locations, returns 0 on success */
62
static int memguard_check(unsigned short rmodseg, char *cmdlinebuf) {
62
static int memguard_check(unsigned short rmodseg, char *cmdlinebuf) {
63
  /* check RMOD signature (would be overwritten in case of stack overflow */
63
  /* check RMOD signature (would be overwritten in case of stack overflow */
64
  static char msg[] = "!! MEMORY CORRUPTION ## DETECTED !!";
64
  static char msg[] = "!! MEMORY CORRUPTION ## DETECTED !!";
65
  unsigned short far *rmodsig = MK_FP(rmodseg, 0x100 + 6);
65
  unsigned short far *rmodsig = MK_FP(rmodseg, 0x100 + 6);
-
 
66
  unsigned char far *rmod = MK_FP(rmodseg, 0);
-
 
67
 
66
  if (*rmodsig != 0x2019) {
68
  if (*rmodsig != 0x2019) {
67
    msg[22] = '1';
69
    msg[22] = '1';
68
    outputnl(msg);
-
 
69
    printf("rmodseg = %04X ; *rmodsig = %04X\r\n", rmodseg, *rmodsig);
-
 
70
    return(1);
70
    goto FAIL;
71
  }
71
  }
-
 
72
 
72
  /* check last BUFFER byte */
73
  /* check last BUFFER byte */
73
  if (BUFFER[sizeof(BUFFER) - 1] != 0xC7) {
74
  if (BUFFER[sizeof(BUFFER) - 1] != 0xC7) {
74
    msg[22] = '2';
75
    msg[22] = '2';
75
    outputnl(msg);
-
 
76
    return(2);
76
    goto FAIL;
77
  }
77
  }
-
 
78
 
78
  /* check last cmdlinebuf byte */
79
  /* check last cmdlinebuf byte */
79
  if (cmdlinebuf[CMDLINE_MAXLEN] != 0xC7) {
80
  if (cmdlinebuf[CMDLINE_MAXLEN] != 0xC7) {
80
    msg[22] = '3';
81
    msg[22] = '3';
-
 
82
    goto FAIL;
-
 
83
  }
-
 
84
 
-
 
85
  /* check rmod exec buf */
-
 
86
  if (rmod[RMOD_OFFSET_EXECPROG + 127] != 0) {
81
    outputnl(msg);
87
    msg[22] = '4';
-
 
88
    goto FAIL;
-
 
89
  }
-
 
90
 
-
 
91
  /* check rmod exec stdin buf */
-
 
92
  if (rmod[RMOD_OFFSET_STDINFILE + 127] != 0) {
-
 
93
    msg[22] = '5';
82
    return(3);
94
    goto FAIL;
83
  }
95
  }
-
 
96
 
-
 
97
  /* check rmod exec stdout buf */
-
 
98
  if (rmod[RMOD_OFFSET_STDOUTFILE + 127] != 0) {
-
 
99
    msg[22] = '6';
-
 
100
    goto FAIL;
-
 
101
  }
-
 
102
 
84
  /* all good */
103
  /* else all good */
85
  return(0);
104
  return(0);
-
 
105
 
-
 
106
  /* error handling */
-
 
107
  FAIL:
-
 
108
  outputnl(msg);
-
 
109
  return(1);
86
}
110
}
87
 
111
 
88
 
112
 
89
/* parses command line the hard way (directly from PSP) */
113
/* parses command line the hard way (directly from PSP) */
90
static void parse_argv(struct config *cfg) {
114
static void parse_argv(struct config *cfg) {
Line 419... Line 443...
419
  RUNCMDFILE:
443
  RUNCMDFILE:
420
 
444
 
421
  /* special handling of batch files */
445
  /* special handling of batch files */
422
  if ((ext != NULL) && (imatch(ext, "bat"))) {
446
  if ((ext != NULL) && (imatch(ext, "bat"))) {
423
    /* copy truename of the bat file to rmod buff */
447
    /* copy truename of the bat file to rmod buff */
424
    for (i = 0; cmdfile[i] != 0; i++) rmod->batfile[i] = cmdfile[i];
-
 
425
    rmod->batfile[i] = 0;
448
    _fstrcpy(rmod->batfile, cmdfile);
426
 
449
 
427
    /* explode args of the bat file and store them in rmod buff */
450
    /* explode args of the bat file and store them in rmod buff */
428
    cmd_explode(buff, cmdline, NULL);
451
    cmd_explode(buff, cmdline, NULL);
429
    _fmemcpy(rmod->batargv, buff, sizeof(rmod->batargv));
452
    _fmemcpy(rmod->batargv, buff, sizeof(rmod->batargv));
430
 
453
 
Line 435... Line 458...
435
    if (rmod->flags & FLAG_ECHOFLAG) rmod->flags |= FLAG_ECHO_BEFORE_BAT;
458
    if (rmod->flags & FLAG_ECHOFLAG) rmod->flags |= FLAG_ECHO_BEFORE_BAT;
436
    return;
459
    return;
437
  }
460
  }
438
 
461
 
439
  /* copy full filename to execute, along with redirected files (if any) */
462
  /* copy full filename to execute, along with redirected files (if any) */
440
  for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
463
  _fstrcpy(rmod_execprog, cmdfile);
-
 
464
 
441
  rmod_execprog[i++] = 0;
465
  /* copy stdin file if a redirection is needed */
442
  if (redir->stdinfile) {
466
  if (redir->stdinfile) {
443
    unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
467
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
444
    unsigned short t;
-
 
445
    *farptr = i;
-
 
446
    for (t = 0;; t++) {
-
 
447
      rmod_execprog[i++] = redir->stdinfile[t];
468
    _fstrcpy(farptr, redir->stdinfile);
448
      if (redir->stdinfile[t] == 0) break;
-
 
449
    }
-
 
450
  }
469
  }
-
 
470
 
-
 
471
  /* same for stdout file */
451
  if (redir->stdoutfile) {
472
  if (redir->stdoutfile) {
452
    unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
473
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
453
    unsigned short t;
474
    unsigned short far *farptr16 = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
454
    *farptr = i;
-
 
455
    for (t = 0;; t++) {
-
 
456
      rmod_execprog[i++] = redir->stdoutfile[t];
475
    _fstrcpy(farptr, redir->stdoutfile);
457
      if (redir->stdoutfile[t] == 0) break;
-
 
458
    }
-
 
459
    /* openflag */
476
    /* openflag */
460
    farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
-
 
461
    *farptr = redir->stdout_openflag;
477
    *farptr16 = redir->stdout_openflag;
462
  }
478
  }
463
 
479
 
464
  /* copy cmdtail to rmod's PSP and compute its len */
480
  /* copy cmdtail to rmod's PSP and compute its len */
465
  for (i = 0; cmdtail[i] != 0; i++) rmod_cmdtail[i] = cmdtail[i];
481
  for (i = 0; cmdtail[i] != 0; i++) rmod_cmdtail[i] = cmdtail[i];
466
  rmod_cmdtail[i] = '\r';
482
  rmod_cmdtail[i] = '\r';