Subversion Repositories SvarDOS

Rev

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

Rev 485 Rev 490
Line 85... Line 85...
85
  unsigned char flags; /* command.com flags, as defined in rmodinit.h */
85
  unsigned char flags; /* command.com flags, as defined in rmodinit.h */
86
  char *execcmd;
86
  char *execcmd;
87
  unsigned short envsiz;
87
  unsigned short envsiz;
88
};
88
};
89
 
89
 
-
 
90
/* max length of the cmdline storage (bytes) - includes also max length of
-
 
91
 * line loaded from a BAT file (no more than 255 bytes!) */
-
 
92
#define CMDLINE_MAXLEN 255
-
 
93
 
-
 
94
 
-
 
95
/* sets guard values at a few places in memory for later detection of
-
 
96
 * overflows via memguard_check() */
-
 
97
static void memguard_set(void) {
-
 
98
  BUFFER[sizeof(BUFFER) - 1] = 0xC7;
-
 
99
  BUFFER[sizeof(BUFFER) - (CMDLINE_MAXLEN + 3)] = 0xC7;
-
 
100
}
-
 
101
 
-
 
102
 
-
 
103
/* checks for valguards at specific memory locations, returns 0 on success */
-
 
104
static int memguard_check(unsigned short rmodseg) {
-
 
105
  /* check RMOD signature (would be overwritten in case of stack overflow */
-
 
106
  static char msg[] = "!! MEMORY CORRUPTION ## DETECTED !!";
-
 
107
  unsigned short far *rmodsig = MK_FP(rmodseg, 0x100 + 6);
-
 
108
  if (*rmodsig != 0x2019) {
-
 
109
    msg[22] = '1';
-
 
110
    outputnl(msg);
-
 
111
    printf("rmodseg = %04X ; *rmodsig = %04X\r\n", rmodseg, *rmodsig);
-
 
112
    return(1);
-
 
113
  }
-
 
114
  /* check last BUFFER byte (could be overwritten by cmdline) */
-
 
115
  if (BUFFER[sizeof(BUFFER) - 1] != 0xC7) {
-
 
116
    msg[22] = '2';
-
 
117
    outputnl(msg);
-
 
118
    return(2);
-
 
119
  }
-
 
120
  /* check that cmdline BUFFER's end hasn't been touched by something else */
-
 
121
  if (BUFFER[sizeof(BUFFER) - (CMDLINE_MAXLEN + 3)] != 0xC7) {
-
 
122
    msg[22] = '3';
-
 
123
    outputnl(msg);
-
 
124
    return(3);
-
 
125
  }
-
 
126
  /* all good */
-
 
127
  return(0);
-
 
128
}
-
 
129
 
90
 
130
 
91
/* parses command line the hard way (directly from PSP) */
131
/* parses command line the hard way (directly from PSP) */
92
static void parse_argv(struct config *cfg) {
132
static void parse_argv(struct config *cfg) {
93
  unsigned short i;
133
  unsigned short i;
94
  const unsigned char *cmdlinelen = (unsigned char *)0x80;
134
  const unsigned char *cmdlinelen = (unsigned char *)0x80;
Line 605... Line 645...
605
  rmod->batnextline = 0;
645
  rmod->batnextline = 0;
606
  return(-1);
646
  return(-1);
607
}
647
}
608
 
648
 
609
 
649
 
610
/* max length of the cmdline storage (bytes) - includes also max length of
-
 
611
 * line loaded from a BAT file (no more than 255 bytes!) */
-
 
612
#define CMDLINE_MAXLEN 255
-
 
613
 
-
 
614
int main(void) {
650
int main(void) {
615
  static struct config cfg;
651
  static struct config cfg;
616
  static unsigned short far *rmod_envseg;
652
  static unsigned short far *rmod_envseg;
617
  static unsigned short far *lastexitcode;
653
  static unsigned short far *lastexitcode;
618
  static struct rmod_props far *rmod;
654
  static struct rmod_props far *rmod;
Line 636... Line 672...
636
     * die asap, because the command has been executed already, so I no longer
672
     * die asap, because the command has been executed already, so I no longer
637
     * have a purpose in life */
673
     * have a purpose in life */
638
    if (rmod->flags & FLAG_EXEC_AND_QUIT) sayonara(rmod);
674
    if (rmod->flags & FLAG_EXEC_AND_QUIT) sayonara(rmod);
639
  }
675
  }
640
 
676
 
-
 
677
  /* install a few guardvals in memory to detect some cases of overflows */
-
 
678
  memguard_set();
-
 
679
 
641
  rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
680
  rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
642
  lastexitcode = MK_FP(rmod->rmodseg, RMOD_OFFSET_LEXITCODE);
681
  lastexitcode = MK_FP(rmod->rmodseg, RMOD_OFFSET_LEXITCODE);
643
 
682
 
644
  /* make COMPSEC point to myself */
683
  /* make COMPSEC point to myself */
645
  set_comspec_to_self(*rmod_envseg);
684
  set_comspec_to_self(*rmod_envseg);
Line 664... Line 703...
664
    SKIP_NEWLINE:
703
    SKIP_NEWLINE:
665
 
704
 
666
    /* cancel any redirections that may have been set up before */
705
    /* cancel any redirections that may have been set up before */
667
    redir_revert();
706
    redir_revert();
668
 
707
 
-
 
708
    /* memory check */
-
 
709
    memguard_check(rmod->rmodseg);
-
 
710
 
669
    /* preset cmdline to point at the end of my general-purpose buffer */
711
    /* preset cmdline to point at the end of my general-purpose buffer (with
-
 
712
     * one extra byte for the NULL terminator and another for memguard val) */
670
    cmdline = BUFFER + sizeof(BUFFER) - (CMDLINE_MAXLEN + 1);
713
    cmdline = BUFFER + sizeof(BUFFER) - (CMDLINE_MAXLEN + 2);
671
 
714
 
672
    /* (re)load translation strings if needed */
715
    /* (re)load translation strings if needed */
673
    nls_langreload(BUFFER, *rmod_envseg);
716
    nls_langreload(BUFFER, *rmod_envseg);
674
 
717
 
675
    /* skip user input if I have a command to exec (/C or /K) */
718
    /* skip user input if I have a command to exec (/C or /K) */