@@ -190,6 +190,30 @@ inline const char *my_strstr(const char *str, const char *search)
190190{
191191 return (const char *)_mbsstr((const unsigned char *)(str), (const unsigned char *)(search));
192192}
193+ inline char *my_strcasestr(char *str, const char *search)
194+ {
195+ int len1 = (int)_mbstrlen(str);
196+ int len2 = (int)_mbstrlen(search);
197+
198+ for(int pos = 0; pos < len1 - len2 + 1; pos++) {
199+ if(_mbsnicmp((unsigned char *)str + pos, (const unsigned char *)search, len2) == 0) {
200+ return str + pos;
201+ }
202+ }
203+ return NULL;
204+ }
205+ inline const char *my_strcasestr(const char *str, const char *search)
206+ {
207+ int len1 = (int)_mbstrlen(str);
208+ int len2 = (int)_mbstrlen(search);
209+
210+ for(int pos = 0; pos < len1 - len2 + 1; pos++) {
211+ if(_mbsnicmp((const unsigned char *)str + pos, (const unsigned char *)search, len2) == 0) {
212+ return str + pos;
213+ }
214+ }
215+ return NULL;
216+ }
193217inline char *my_strtok(char *tok, const char *del)
194218{
195219 return (char *)_mbstok((unsigned char *)(tok), (const unsigned char *)(del));
@@ -210,6 +234,7 @@ inline char *my_strupr(char *str)
210234#define my_strchr(str, chr) strchr((str), (chr))
211235#define my_strrchr(str, chr) strrchr((str), (chr))
212236#define my_strstr(str, search) strstr((str), (search))
237+ #define my_strcasestr(str, search) strcasestr((str), (search))
213238#define my_strtok(tok, del) strtok((tok), (del))
214239#define my_strtok_s(tok, del, context) strtok_s((tok), (del), (context))
215240#define my_strupr(str) _strupr((str))
@@ -7811,7 +7836,6 @@ int msdos_hma_mem_get_free(int *available_offset)
78117836
78127837void msdos_env_set_argv(int env_seg, const char *argv)
78137838{
7814- int env_size = ((mcb_t *)(mem + ((env_seg - 1) << 4)))->paragraphs * 16;
78157839 char *env = (char *)(mem + (env_seg << 4));
78167840 char *dst = env;
78177841
@@ -7870,7 +7894,6 @@ const char *msdos_env_get(int env_seg, const char *name)
78707894
78717895void msdos_env_set(int env_seg, const char *name, const char *value)
78727896{
7873- int env_size = ((mcb_t *)(mem + ((env_seg - 1) << 4)))->paragraphs * 16;
78747897 char *buf = (char *)malloc(env_size + 1);
78757898 char *src = buf;
78767899 char *env = (char *)(mem + (env_seg << 4));
@@ -9188,28 +9211,24 @@ int msdos_process_exec(const char *cmd, param_block_t *param, UINT8 al, bool fir
91889211 }
91899212
91909213 // copy environment
9191- int parent_env_seg, parent_env_size;
91929214 int umb_linked, env_seg, psp_seg;
91939215
9194- if(param->env_seg == 0) {
9195- parent_env_seg = parent_psp->env_seg;
9196- } else {
9197- parent_env_seg = param->env_seg;
9198- }
9199- parent_env_size = ((mcb_t *)(mem + ((parent_env_seg - 1) << 4)))->paragraphs * 16;
9200-
92019216 if((umb_linked = msdos_mem_get_umb_linked()) != 0) {
92029217 msdos_mem_unlink_umb();
92039218 }
9204- if((env_seg = msdos_mem_alloc(first_mcb, parent_env_size >> 4)) == -1) {
9205- if((env_seg = msdos_mem_alloc(UMB_TOP >> 4, parent_env_size >> 4)) == -1) {
9219+ if((env_seg = msdos_mem_alloc(first_mcb, env_size >> 4)) == -1) {
9220+ if((env_seg = msdos_mem_alloc(UMB_TOP >> 4, env_size >> 4)) == -1) {
92069221 if(umb_linked != 0) {
92079222 msdos_mem_link_umb();
92089223 }
92099224 return(-1);
92109225 }
92119226 }
9212- memcpy(mem + (env_seg << 4), mem + (parent_env_seg << 4), parent_env_size);
9227+ if(param->env_seg == 0) {
9228+ memcpy(mem + (env_seg << 4), mem + (parent_psp->env_seg << 4), env_size);
9229+ } else {
9230+ memcpy(mem + (env_seg << 4), mem + (param->env_seg << 4), env_size);
9231+ }
92139232 msdos_env_set_argv(env_seg, msdos_short_full_path(path));
92149233
92159234 // check exe header
@@ -22395,6 +22414,16 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2239522414 const char *path, *short_path;
2239622415 wchar_t wc_path[ENV_SIZE];
2239722416
22417+ env_size = standard_env ? 2048 : 8192;
22418+
22419+ if(argc > 1 && (_stricmp(argv[0], "COMMAND.COM") == 0 || _stricmp(argv[0], "COMMAND") == 0)) {
22420+ for(int i = 1; i < argc; i++) {
22421+ if(_strnicmp(argv[i], "/E:", 3) == 0) {
22422+ env_size = ((atoi(&argv[i][3]) + 15) >> 4) << 4;
22423+ env_size = max(160, min(32768, env_size));
22424+ }
22425+ }
22426+ }
2239822427 env_append[0] = env_msdos_path[0] = env_path[0] = env_temp[0] = '\0';
2239922428
2240022429 if(GetEnvironmentVariableW(L"MSDOS_APPEND", wc_path, ENV_SIZE) != 0) {
@@ -22545,13 +22574,21 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2254522574 } else {
2254622575 sprintf((char *)(mem + (env_seg << 4) + ofs), "%s=%s", name, value);
2254722576 }
22548- ofs += (int)strlen((char *)(mem + (env_seg << 4) + ofs)) + 1;
22577+ int len = (int)strlen((char *)(mem + (env_seg << 4) + ofs));
22578+ if(ofs + len + 1 + (2 + (8 + 1 + 3)) + 2 > env_size) {
22579+ fatalerror("too many environments\n");
22580+ }
22581+ ofs += len + 1;
2254922582 }
2255022583 }
2255122584 if(!append_added && env_append[0] != '\0') {
2255222585 #define SET_ENV(name, value) { \
2255322586 sprintf((char *)(mem + (env_seg << 4) + ofs), "%s=%s", name, value); \
22554- ofs += (int)strlen((char *)(mem + (env_seg << 4) + ofs)) + 1; \
22587+ int len = (int)strlen((char *)(mem + (env_seg << 4) + ofs)); \
22588+ if(ofs + len + 1 + (2 + (8 + 1 + 3)) + 2 > env_size) { \
22589+ fatalerror("too many environments\n"); \
22590+ } \
22591+ ofs += len + 1; \
2255522592 }
2255622593 SET_ENV("APPEND", env_append);
2255722594 }
@@ -22632,16 +22669,6 @@ int msdos_init(int argc, char *argv[], char *envp[], int standard_env)
2263222669 }
2263322670 SET_ENV("TZ", tz_value);
2263422671 }
22635- int env_size = (ofs + 1) + (2 + MAX_PATH + 1);
22636- env_size = ((env_size + 15) >> 4) << 4;
22637- if(env_size > 32768) {
22638- fatalerror("too many environment variables (size:%d max:32768)\nspecify -e option to load minimum environment variables\n", env_size);
22639- }
22640- if(standard_env) {
22641- env_size = max(env_size + 128, 1024);
22642- } else {
22643- env_size = min(env_size + 512, 32768);
22644- }
2264522672 msdos_mcb_create(seg++, 'M', PSP_SYSTEM, env_size >> 4);
2264622673 seg += (env_size >> 4);
2264722674
0 commit comments