Menu

#226 INSTALL= crashes as it uses memory that it has already given away

freedos13
open
None
5
2018-11-20
2018-11-20
tom ehlert
No

the program below works perfect from command line, but crashes freedos when run as
INSTALL=MEMZERO


//
// MEMZERO.C
//
// allocate all available DOS memory, and memset() it to 0xcc
//
// works perfect in any DOS box, but crashes FreeDOS if run via
//
// INSTALL=MEMZERO
//
// free to use as you see fit
// tom ehlert 20 nov 2018
//
// compile with wcl   -i=%WATCOM%\h memzero.c 
// but shold work with any other compiler as well


#include <stdio.h>
#include <stdlib.h>
#include <dos.h>



//
// fill all free memory with 0xcc
//
// helps detect problems when the kernel INSTALL=
// but uses memory (memcpy, strlen, ...)
// in freed memory
//



void main(void)
{                

    union REGS regs;

    printf("filling memory with 0xcc\n");

    regs.x.ax = 0x5803;         // set UMB link on
    regs.x.bx = 1;
    intdos(&regs, &regs);

    for (;;)
        {
        unsigned loop, iloop;
                        // dos_alloc largest block possible 
        union REGS regs;
        regs.x.ax = 0x4800;
        regs.x.bx = 0xffff;
        intdos(&regs, &regs);

                            // this will fail, but set BX to largest available
        regs.x.ax = 0x4800;
        intdos(&regs, &regs);

        if (regs.x.cflag)   // done
            break;

        printf("allocated at %04x:0000 -  %04x:0000: 0x%04x0= %lu byte\n",  regs.x.ax, regs.x.ax + regs.x.bx,regs.x.bx, (unsigned long)regs.x.bx*16);

        for (loop = 0; loop < regs.x.bx; loop++)
            for (iloop = 0; iloop < 16; iloop++)
                {
                *(char far *)MK_FP(regs.x.ax+loop,iloop) = 0xcc;    // 0xcc = INT 3
                }
        }
    regs.x.ax = 0x5803;         // set UMB link off
    regs.x.bx = 0;
    intdos(&regs, &regs);
    exit(0);
}

reason:

CONFIG.C, line ~2566
STATIC VOID InstallExec(struct instCmds *icmd)
{                            
...
  args--;
  *args = strlen(&args[1]);

uses strlen(), but the area for strlen (C runtime library) has already been added to free DOS memory.

changing this to

int init_strlen(char *s)
{
    int i;
    for (i = 0; *s != 0; s++)
        ;
    return i;   
}                  

STATIC VOID InstallExec(struct instCmds *icmd)
{                            
....
  *args = init_strlen(&args[1]);

solves the problem.

Tom

1 Attachments

Discussion


Log in to post a comment.

Auth0 Logo