/svarcom/trunk/command.c |
---|
870,16 → 870,16 |
if (cmdline[0] == '@') cmdline++; |
} else { |
unsigned char far *rmod_inputbuf = MK_FP(rmod->rmodseg, RMOD_OFFSET_INPUTBUF); |
unsigned short far *rmod_stacksig = MK_FP(rmod->rmodseg, RMOD_OFFSET_STACKSIG); |
/* invalidate input history if it appears to be damaged (could occur |
* because of a stack overflow, for example if some stack-hungry TSR is |
* being used) */ |
if (*rmod_stacksig != 0xCAFE) { |
*rmod_stacksig = 0xCAFE; |
rmod_inputbuf[0] = 128; /* max allowed input length */ |
rmod_inputbuf[1] = 0; |
rmod_inputbuf[2] = '\r'; |
/* printf("STACK OVERFLOW DETECTED: HISTORY FLUSHED\r\n"); */ |
if ((rmod_inputbuf[0] != 128) || (rmod_inputbuf[rmod_inputbuf[1] + 2] != '\r') || (rmod_inputbuf[rmod_inputbuf[1] + 3] != 0xCA) || (rmod_inputbuf[rmod_inputbuf[1] + 4] != 0xFE)) { |
rmod_inputbuf[0] = 128; /* max allowed input length */ |
rmod_inputbuf[1] = 0; /* string len stored in buffer */ |
rmod_inputbuf[2] = '\r'; /* string terminator */ |
rmod_inputbuf[3] = 0xCA; /* trailing signature */ |
rmod_inputbuf[4] = 0xFE; /* trailing signature */ |
outputnl("SvarCOM: stack overflow detected, command history flushed (this is not a bug)"); |
} |
/* interactive mode: display prompt (if echo enabled) and wait for user |
* command line */ |
886,6 → 886,9 |
if (rmod->flags & FLAG_ECHOFLAG) build_and_display_prompt(BUFFER, *rmod_envseg); |
/* collect user input */ |
cmdline_getinput(rmod->rmodseg, RMOD_OFFSET_INPUTBUF); |
/* append stack-overflow detection signature to the end of the input buffer */ |
rmod_inputbuf[rmod_inputbuf[1] + 3] = 0xCA; /* trailing signature */ |
rmod_inputbuf[rmod_inputbuf[1] + 4] = 0xFE; /* trailing signature */ |
/* copy it to local cmdline */ |
if (rmod_inputbuf[1] != 0) _fmemcpy(cmdline, rmod_inputbuf + 2, rmod_inputbuf[1]); |
cmdline[rmod_inputbuf[1]] = 0; /* zero-terminate local buff (original is '\r'-terminated) */ |
/svarcom/trunk/history.txt |
---|
12,6 → 12,7 |
- multi-lang support relies on SvarLANG.lib instead of its own routines |
- stack overflow detection degrades gracefully by invalidating command-line |
history (useful if a stack-hungry TSR overflows the RMOD stack) |
- added German translations (kindly provided by Robert Riebisch) |
=== ver 2022.0 (01.02.2022) ================================================== |
/svarcom/trunk/rmod.asm |
---|
25,14 → 25,10 |
; input service at INT 21h,AH=0x0A. |
; This buffer is right before the stack, so in case of a stack overflow event |
; (for example because of a "too ambitious" TSR) only this buffer is damaged, |
; and can be invalidated without much harm. |
INPUTBUF: times 130 db 0 |
; and can be invalidated without much harm. To detect such damage, SvarCOM's |
; transient part is appending a signature at the end of the buffer. |
INPUTBUF: times 132 db 0 ; 130 bytes for the input buffer + 2 for signature |
; This stack sig is a guardian value that is checked by the transient part of |
; SvarCOM to detect possible stack overflows. If a stack overflow occurs, then |
; the INPUTBUFF area above is invalidated and stack signature reverted. |
STACKSIG dw 0xCAFE |
; DOS int 21h functions that I use require at least 40 bytes of stack under |
; DOS-C (FreeDOS) kernel, so here I reserve 64 bytes juste to be sure |
STACKBUF db "XXX SVARCOM RMOD BY MATEUSZ VISTE XXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
/svarcom/trunk/rmodinit.c |
---|
149,9 → 149,11 |
/* mark the input buffer as empty */ |
myptr = MK_FP(rmodseg, RMOD_OFFSET_INPUTBUF); |
myptr[0] = 128; |
myptr[1] = 0; |
myptr[2] = '\r'; |
myptr[0] = 128; /* max acceptable length */ |
myptr[1] = 0; /* len of currently stored history string */ |
myptr[2] = '\r'; /* string terminator */ |
myptr[3] = 0xCA; /* signature to detect stack overflow damaging the buffer */ |
myptr[4] = 0xFE; /* 2nd byte of the signature */ |
/* prepare result (rmod props) */ |
res = MK_FP(rmodseg, 0x100 + rmodcore_len); |
/svarcom/trunk/rmodinit.h |
---|
52,7 → 52,6 |
#define RMOD_OFFSET_ENVSEG 0x2C /* stored in rmod's PSP */ |
#define RMOD_OFFSET_INPUTBUF (0x100 + 0x08) |
#define RMOD_OFFSET_STACKSIG (0x100 + 0x8A) /* 0xCAFE */ |
#define RMOD_OFFSET_COMSPECPTR (0x100 + 0xCE) |
#define RMOD_OFFSET_BOOTDRIVE (0x100 + 0xD0) |
#define RMOD_OFFSET_LEXITCODE (0x100 + 0xDF) |