• R/O
  • SSH
  • HTTPS

svardos: Commit


Commit MetaInfo

Revision548 (tree)
Time2022-01-06 00:22:09
Authormateuszviste

Log Message

stdin/stdout files are stored in separate rmod buffers to avoid overflows and simplify code, also added extra memory guards

Change Summary

Incremental Difference

--- svarcom/trunk/command.c (revision 547)
+++ svarcom/trunk/command.c (revision 548)
@@ -63,26 +63,50 @@
6363 /* check RMOD signature (would be overwritten in case of stack overflow */
6464 static char msg[] = "!! MEMORY CORRUPTION ## DETECTED !!";
6565 unsigned short far *rmodsig = MK_FP(rmodseg, 0x100 + 6);
66+ unsigned char far *rmod = MK_FP(rmodseg, 0);
67+
6668 if (*rmodsig != 0x2019) {
6769 msg[22] = '1';
68- outputnl(msg);
69- printf("rmodseg = %04X ; *rmodsig = %04X\r\n", rmodseg, *rmodsig);
70- return(1);
70+ goto FAIL;
7171 }
72+
7273 /* check last BUFFER byte */
7374 if (BUFFER[sizeof(BUFFER) - 1] != 0xC7) {
7475 msg[22] = '2';
75- outputnl(msg);
76- return(2);
76+ goto FAIL;
7777 }
78+
7879 /* check last cmdlinebuf byte */
7980 if (cmdlinebuf[CMDLINE_MAXLEN] != 0xC7) {
8081 msg[22] = '3';
81- outputnl(msg);
82- return(3);
82+ goto FAIL;
8383 }
84- /* all good */
84+
85+ /* check rmod exec buf */
86+ if (rmod[RMOD_OFFSET_EXECPROG + 127] != 0) {
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';
94+ goto FAIL;
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+
103+ /* else all good */
85104 return(0);
105+
106+ /* error handling */
107+ FAIL:
108+ outputnl(msg);
109+ return(1);
86110 }
87111
88112
@@ -421,8 +445,7 @@
421445 /* special handling of batch files */
422446 if ((ext != NULL) && (imatch(ext, "bat"))) {
423447 /* 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);
426449
427450 /* explode args of the bat file and store them in rmod buff */
428451 cmd_explode(buff, cmdline, NULL);
@@ -437,28 +460,21 @@
437460 }
438461
439462 /* copy full filename to execute, along with redirected files (if any) */
440- for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
441- rmod_execprog[i++] = 0;
463+ _fstrcpy(rmod_execprog, cmdfile);
464+
465+ /* copy stdin file if a redirection is needed */
442466 if (redir->stdinfile) {
443- unsigned short 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];
448- if (redir->stdinfile[t] == 0) break;
449- }
467+ char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
468+ _fstrcpy(farptr, redir->stdinfile);
450469 }
470+
471+ /* same for stdout file */
451472 if (redir->stdoutfile) {
452- unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
453- unsigned short t;
454- *farptr = i;
455- for (t = 0;; t++) {
456- rmod_execprog[i++] = redir->stdoutfile[t];
457- if (redir->stdoutfile[t] == 0) break;
458- }
473+ char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
474+ unsigned short far *farptr16 = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
475+ _fstrcpy(farptr, redir->stdoutfile);
459476 /* openflag */
460- farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
461- *farptr = redir->stdout_openflag;
477+ *farptr16 = redir->stdout_openflag;
462478 }
463479
464480 /* copy cmdtail to rmod's PSP and compute its len */
--- svarcom/trunk/rmodinit.h (revision 547)
+++ svarcom/trunk/rmodinit.h (revision 548)
@@ -50,11 +50,11 @@
5050 #define RMOD_OFFSET_LEXITCODE (0x100 + 0x5B)
5151 #define RMOD_OFFSET_EXECPARAM (0x100 + 0x5C)
5252 #define RMOD_OFFSET_EXECPROG (0x100 + 0x6A)
53-#define RMOD_OFFSET_STDOUTFILE (0x100 + 0xEA)
54-#define RMOD_OFFSET_STDINFILE (0x100 + 0xEC)
55-#define RMOD_OFFSET_STDOUTAPP (0x100 + 0xEE)
56-#define RMOD_OFFSET_BRKHANDLER (0x100 + 0xF0)
57-#define RMOD_OFFSET_ROUTINE (0x100 + 0xF2)
53+#define RMOD_OFFSET_STDINFILE (0x100 + 0xEA)
54+#define RMOD_OFFSET_STDOUTFILE (0x100 + 0x16A)
55+#define RMOD_OFFSET_STDOUTAPP (0x100 + 0x1EA)
56+#define RMOD_OFFSET_BRKHANDLER (0x100 + 0x1EC)
57+#define RMOD_OFFSET_ROUTINE (0x100 + 0x1EE)
5858
5959 struct rmod_props far *rmod_install(unsigned short envsize, unsigned char *rmodcore, unsigned short rmodcore_len);
6060 struct rmod_props far *rmod_find(unsigned short rmodcore_len);
Show on old repository browser