Add Beta2 patch: Fix autoexec overflow.
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2729
This commit is contained in:
parent
fdd16dea1a
commit
d78d597f92
4 changed files with 62 additions and 52 deletions
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: shell.h,v 1.19 2007-01-08 19:45:37 qbix79 Exp $ */
|
||||
/* $Id: shell.h,v 1.20 2007-01-08 19:59:06 qbix79 Exp $ */
|
||||
|
||||
#ifndef DOSBOX_SHELL_H
|
||||
#define DOSBOX_SHELL_H
|
||||
|
@ -154,11 +154,11 @@ static inline char* ExpandDot(char*args, char* buffer) {
|
|||
class AutoexecObject{
|
||||
private:
|
||||
bool installed;
|
||||
char buf[256];
|
||||
std::string buf;
|
||||
public:
|
||||
AutoexecObject():installed(false){};
|
||||
void Install(char * line,...);
|
||||
void InstallBefore(char* line, ...);
|
||||
AutoexecObject():installed(false){ };
|
||||
void Install(std::string const &in);
|
||||
void InstallBefore(std::string const &in);
|
||||
~AutoexecObject();
|
||||
private:
|
||||
void CreateAutoexec(void);
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include "dosbox.h"
|
||||
#include "inout.h"
|
||||
#include "mixer.h"
|
||||
|
@ -26,6 +28,7 @@
|
|||
#include "shell.h"
|
||||
#include "math.h"
|
||||
#include "regs.h"
|
||||
using namespace std;
|
||||
|
||||
//Extra bits of precision over normal gus
|
||||
#define WAVE_BITS 2
|
||||
|
@ -82,12 +85,12 @@ struct GFGus {
|
|||
float delay;
|
||||
} timers[2];
|
||||
Bit32u rate;
|
||||
Bit16u portbase;
|
||||
Bit8u dma1;
|
||||
Bit8u dma2;
|
||||
Bitu portbase;
|
||||
Bitu dma1;
|
||||
Bitu dma2;
|
||||
|
||||
Bit16u irq1;
|
||||
Bit16u irq2;
|
||||
Bitu irq1;
|
||||
Bitu irq2;
|
||||
|
||||
char ultradir[512];
|
||||
bool irqenabled;
|
||||
|
@ -861,10 +864,15 @@ public:
|
|||
myGUS.gRegData=0x0;
|
||||
int portat = 0x200+GUS_BASE;
|
||||
// ULTRASND=Port,DMA1,DMA2,IRQ1,IRQ2
|
||||
autoexecline[0].Install("SET ULTRASND=%3X,%d,%d,%d,%d",portat,myGUS.dma1,myGUS.dma2,myGUS.irq1,myGUS.irq2);
|
||||
autoexecline[1].Install("SET ULTRADIR=%s", myGUS.ultradir);
|
||||
// Create autoexec.bat lines
|
||||
ostringstream temp;
|
||||
temp << "SET ULTRASND=" << hex << setw(3) << portat << ","
|
||||
<< dec << myGUS.dma1 << "," << myGUS.dma2 << ","
|
||||
<< myGUS.irq1 << "," << myGUS.irq2 << ends;
|
||||
autoexecline[0].Install(temp.str());
|
||||
autoexecline[1].Install(std::string("SET ULTRADIR=")+ myGUS.ultradir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
~GUS() {
|
||||
if(machine!=MCH_VGA) return;
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: sblaster.cpp,v 1.60 2007-01-08 19:45:40 qbix79 Exp $ */
|
||||
/* $Id: sblaster.cpp,v 1.61 2007-01-08 19:59:06 qbix79 Exp $ */
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "dosbox.h"
|
||||
|
@ -29,6 +31,7 @@
|
|||
#include "setup.h"
|
||||
#include "support.h"
|
||||
#include "shell.h"
|
||||
using namespace std;
|
||||
|
||||
void MIDI_RawOutByte(Bit8u data);
|
||||
bool MIDI_Available(void);
|
||||
|
@ -141,8 +144,8 @@ struct SB_INFO {
|
|||
} adpcm;
|
||||
struct {
|
||||
Bitu base;
|
||||
Bit8u irq;
|
||||
Bit8u dma8,dma16;
|
||||
Bitu irq;
|
||||
Bitu dma8,dma16;
|
||||
} hw;
|
||||
struct {
|
||||
Bits value;
|
||||
|
@ -1314,11 +1317,14 @@ public:
|
|||
if (sb.type == SBT_16) sb.chan->Enable(true);
|
||||
else sb.chan->Enable(false);
|
||||
|
||||
char hdma[8]="";
|
||||
if (sb.type==SBT_16) {
|
||||
sprintf(hdma,"H%d ",sb.hw.dma16);
|
||||
}
|
||||
autoexecline.Install("SET BLASTER=A%3X I%d D%d %sT%d",sb.hw.base,sb.hw.irq,sb.hw.dma8,hdma,sb.type);
|
||||
// Create set blaster line
|
||||
ostringstream temp;
|
||||
temp << "SET BLASTER=A" << setw(3)<< hex << sb.hw.base
|
||||
<< " I" << dec << sb.hw.irq << " D"<< sb.hw.dma8;
|
||||
if (sb.type==SBT_16) temp << " H" << sb.hw.dma16;
|
||||
temp << " T" << static_cast<unsigned int>(sb.type) << ends;
|
||||
|
||||
autoexecline.Install(temp.str());
|
||||
|
||||
/* Soundblaster midi interface */
|
||||
if (!MIDI_Available()) sb.midi = false;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: shell.cpp,v 1.78 2007-01-08 19:45:42 qbix79 Exp $ */
|
||||
/* $Id: shell.cpp,v 1.79 2007-01-08 19:59:06 qbix79 Exp $ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -48,16 +48,11 @@ typedef std::list<std::string>::iterator auto_it;
|
|||
|
||||
void VFILE_Remove(const char *name);
|
||||
|
||||
void AutoexecObject::Install(char* line,...) {
|
||||
if(GCC_UNLIKELY(installed)) E_Exit("autoexec: allready created %s",buf);
|
||||
void AutoexecObject::Install(const std::string &in) {
|
||||
if(GCC_UNLIKELY(installed)) E_Exit("autoexec: allready created %s",buf.c_str());
|
||||
installed = true;
|
||||
va_list msg;
|
||||
|
||||
va_start(msg,line);
|
||||
vsprintf(buf,line,msg);
|
||||
va_end(msg);
|
||||
autoexec_strings.push_back(std::string(buf));
|
||||
|
||||
buf = in;
|
||||
autoexec_strings.push_back(buf);
|
||||
this->CreateAutoexec();
|
||||
|
||||
//autoexec.bat is normally created AUTOEXEC_Init.
|
||||
|
@ -65,7 +60,10 @@ void AutoexecObject::Install(char* line,...) {
|
|||
//we have to update the envirionment to display changes
|
||||
|
||||
if(first_shell) {
|
||||
char buf2[256]; strcpy(buf2,buf);//used in shell.h
|
||||
//create a copy as the string will be modified
|
||||
std::string::size_type n = buf.size();
|
||||
char* buf2 = new char[n + 1];
|
||||
safe_strncpy(buf2, buf.c_str(), n + 1);
|
||||
if((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){
|
||||
char* after_set = buf2 + 4;//move to variable that is being set
|
||||
char* test = strpbrk(after_set,"=");
|
||||
|
@ -74,18 +72,15 @@ void AutoexecObject::Install(char* line,...) {
|
|||
//If the shell is running/exists update the environment
|
||||
first_shell->SetEnv(after_set,test);
|
||||
}
|
||||
delete [] buf2;
|
||||
}
|
||||
}
|
||||
|
||||
void AutoexecObject::InstallBefore(char* line,...) {
|
||||
if(GCC_UNLIKELY(installed)) E_Exit("autoexec: allready created %s",buf);
|
||||
void AutoexecObject::InstallBefore(const std::string &in) {
|
||||
if(GCC_UNLIKELY(installed)) E_Exit("autoexec: allready created %s",buf.c_str());
|
||||
installed = true;
|
||||
va_list msg;
|
||||
|
||||
va_start(msg,line);
|
||||
vsprintf(buf,line,msg);
|
||||
va_end(msg);
|
||||
autoexec_strings.push_front(std::string(buf));
|
||||
buf = in;
|
||||
autoexec_strings.push_front(buf);
|
||||
this->CreateAutoexec();
|
||||
}
|
||||
|
||||
|
@ -98,7 +93,7 @@ void AutoexecObject::CreateAutoexec(void) {
|
|||
size_t auto_len;
|
||||
for(auto_it it= autoexec_strings.begin(); it != autoexec_strings.end(); it++) {
|
||||
auto_len = strlen(autoexec_data);
|
||||
if ((auto_len+strlen((*it).c_str())+3)>AUTOEXEC_SIZE) {
|
||||
if ((auto_len+(*it).length()+3)>AUTOEXEC_SIZE) {
|
||||
E_Exit("SYSTEM:Autoexec.bat file overflow");
|
||||
}
|
||||
sprintf((autoexec_data+auto_len),"%s\r\n",(*it).c_str());
|
||||
|
@ -113,15 +108,19 @@ AutoexecObject::~AutoexecObject(){
|
|||
for(auto_it it = autoexec_strings.begin(); it != autoexec_strings.end(); ) {
|
||||
if((*it) == buf) {
|
||||
it = autoexec_strings.erase(it);
|
||||
std::string::size_type n = buf.size();
|
||||
char* buf2 = new char[n + 1];
|
||||
safe_strncpy(buf2, buf.c_str(), n + 1);
|
||||
// If it's a environment variable remove it from there as well
|
||||
if((strncasecmp(buf,"set ",4) == 0) && (strlen(buf) > 4)){
|
||||
char* after_set = buf + 4;//move to variable that is being set
|
||||
if((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){
|
||||
char* after_set = buf2 + 4;//move to variable that is being set
|
||||
char* test = strpbrk(after_set,"=");
|
||||
if(!test) continue;
|
||||
*test = 0;
|
||||
//If the shell is running/exists update the environment
|
||||
if(first_shell) first_shell->SetEnv(after_set,"");
|
||||
}
|
||||
delete [] buf2;
|
||||
} else it++;
|
||||
}
|
||||
this->CreateAutoexec();
|
||||
|
@ -350,14 +349,14 @@ public:
|
|||
if(echo_off) autoexec_echo.InstallBefore("@echo off");
|
||||
|
||||
/* Install the stuff from the configfile */
|
||||
autoexec[0].Install("%s",extra);
|
||||
autoexec[0].Install(section->data);
|
||||
}
|
||||
|
||||
/* Check to see for extra command line options to be added (before the command specified on commandline) */
|
||||
/* Maximum of extra commands: 10 */
|
||||
Bitu i = 1;
|
||||
while (control->cmdline->FindString("-c",line,true) && (i <= 11))
|
||||
autoexec[i++].Install((char *)line.c_str());
|
||||
autoexec[i++].Install(line);
|
||||
|
||||
/* Check for the -exit switch which causes dosbox to when the command on the commandline has finished */
|
||||
bool addexit = control->cmdline->FindExist("-exit",true);
|
||||
|
@ -375,7 +374,7 @@ public:
|
|||
if (stat(buffer,&test)) goto nomount;
|
||||
}
|
||||
if (test.st_mode & S_IFDIR) {
|
||||
autoexec[12].Install("MOUNT C \"%s\"",buffer);
|
||||
autoexec[12].Install(std::string("MOUNT C \"") + buffer + "\"");
|
||||
autoexec[13].Install("C:");
|
||||
} else {
|
||||
char* name = strrchr(buffer,CROSS_FILESPLIT);
|
||||
|
@ -390,17 +389,14 @@ public:
|
|||
}
|
||||
*name++ = 0;
|
||||
if (access(buffer,F_OK)) goto nomount;
|
||||
autoexec[12].Install("MOUNT C \"%s\"",buffer);
|
||||
autoexec[12].Install(std::string("MOUNT C \"") + buffer + "\"");
|
||||
autoexec[13].Install("C:");
|
||||
upcase(name);
|
||||
if(strstr(name,".BAT") == 0) {
|
||||
autoexec[14].Install(name);
|
||||
} else {
|
||||
/* BATch files are called else exit will not work */
|
||||
char call[CROSS_LEN] = { 0 };
|
||||
strcpy(call,"CALL ");
|
||||
strcat(call,name);
|
||||
autoexec[14].Install(call);
|
||||
/* BATch files are called else exit will not work */
|
||||
autoexec[14].Install(std::string("CALL ") + name);
|
||||
}
|
||||
if(addexit) autoexec[15].Install("exit");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue