1
0
Fork 0

Ensure room before adding environment variable using set. Noted when running a subshell under NC.

Bug left: we don't have a lot of environment space in that case (not the 160 minimum).


Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4200
This commit is contained in:
Peter Veenstra 2019-04-01 16:50:49 +00:00
parent 4a1ef4d3d7
commit 687e3cf058

View file

@ -220,9 +220,16 @@ Bitu Program::GetEnvCount(void) {
}
bool Program::SetEnv(const char * entry,const char * new_string) {
PhysPt env_read=PhysMake(psp->GetEnvironment(),0);
PhysPt env_write=env_read;
char env_string[1024+1];
PhysPt env_read = PhysMake(psp->GetEnvironment(),0);
//Get size of environment.
DOS_MCB mcb(psp->GetEnvironment()-1);
Bit16u envsize = mcb.GetSize()*16;
PhysPt env_write = env_read;
PhysPt env_write_start = env_read;
char env_string[1024+1] = { 0 };
do {
MEM_StrCopy(env_read,env_string,1024);
if (!env_string[0]) break;
@ -235,11 +242,14 @@ bool Program::SetEnv(const char * entry,const char * new_string) {
} while (1);
/* TODO Maybe save the program name sometime. not really needed though */
/* Save the new entry */
//ensure room
if (envsize <= (env_write-env_write_start) + strlen(entry) + 1 + strlen(new_string) + 2) return false;
if (new_string[0]) {
std::string bigentry(entry);
for (std::string::iterator it = bigentry.begin(); it != bigentry.end(); ++it) *it = toupper(*it);
sprintf(env_string,"%s=%s",bigentry.c_str(),new_string);
// sprintf(env_string,"%s=%s",entry,new_string); //oldcode
snprintf(env_string,1024+1,"%s=%s",bigentry.c_str(),new_string);
MEM_BlockWrite(env_write,env_string,(Bitu)(strlen(env_string)+1));
env_write += (PhysPt)(strlen(env_string)+1);
}