53
53
#define mcbNext (mcb ) mcbAssign(mcb, nxtMCB(FP_SEG(mcb)))
54
54
#define DosAlloc (value ) DOSalloc((value), 0xF)
55
55
56
+ #define BLOCKMAX 256
57
+ #define AVAILBLOCKMAX 256
58
+ #define REGIONMAX 64
59
+
56
60
enum error_codes
57
61
{
58
62
err_help = -1 , OK ,
@@ -154,7 +158,7 @@ static int initialise(void)
154
158
optS = 0 ;
155
159
156
160
/* Allocate dynamic memory for some arrays */
157
- if ((block = malloc (256 * sizeof (* block ))) == 0 )
161
+ if ((block = malloc (BLOCKMAX * sizeof (* block ))) == 0 )
158
162
return err_out_of_memory ;
159
163
160
164
#ifdef FEATURE_XMS_SWAP
@@ -177,7 +181,7 @@ static int initialise(void)
177
181
}
178
182
#endif
179
183
180
- if ((umbRegion = malloc (64 * sizeof (* umbRegion ))) == 0 )
184
+ if ((umbRegion = malloc (REGIONMAX * sizeof (* umbRegion ))) == 0 )
181
185
return err_out_of_memory ;
182
186
183
187
/* find the UMB regions */
@@ -348,6 +352,9 @@ static int findUMBRegions(void)
348
352
{
349
353
region -> end = FP_SEG (mcb ) - 1 ;
350
354
if (! (mcb -> mcb_type == 'Z' && 0 == mcb -> mcb_size )) {
355
+ if ((region - umbRegion ) >= REGIONMAX ) {
356
+ return err_out_of_memory ;
357
+ }
351
358
region ++ ;
352
359
region -> start = 0 ;
353
360
}
@@ -371,6 +378,9 @@ static int findUMBRegions(void)
371
378
region -> end = umb_mcb -> mcb_ownerPSP + umb_mcb -> mcb_size - 1 ;
372
379
if ((sig = umb_mcb -> mcb_type ) == 'M' )
373
380
region -> end -- ;
381
+ if ((region - umbRegion ) >= REGIONMAX ) {
382
+ return err_out_of_memory ;
383
+ }
374
384
region ++ ;
375
385
region -> start = 0 ;
376
386
mcbAssign (mcb , FP_SEG (umb_mcb ) + umb_mcb -> mcb_size );
@@ -385,6 +395,9 @@ static int findUMBRegions(void)
385
395
if (sig == 'Z' )
386
396
{
387
397
region -> end = FP_SEG (mcb ) + mcb -> mcb_size ;
398
+ if ((region - umbRegion ) >= REGIONMAX ) {
399
+ return err_out_of_memory ;
400
+ }
388
401
region ++ ;
389
402
break ;
390
403
}
@@ -428,7 +441,7 @@ static int loadhigh_prepare(void)
428
441
dosSetUMBLinkState (1 );
429
442
dosSetAllocStrategy (0 );
430
443
431
- if ((availBlock = malloc (256 * sizeof (* availBlock ))) == 0 )
444
+ if ((availBlock = malloc (AVAILBLOCKMAX * sizeof (* availBlock ))) == 0 )
432
445
return err_out_of_memory ;
433
446
434
447
/* Call to force DOS to catenate any successive free memory blocks */
@@ -487,6 +500,13 @@ static int loadhigh_prepare(void)
487
500
mcb -> mcb_size >= region -> minSize ))
488
501
{
489
502
503
+ if (availBlocks >= AVAILBLOCKMAX ) {
504
+ DOSfree (bl );
505
+ for (i = 0 ; i < availBlocks ; i ++ )
506
+ DOSfree (availBlock [i ]);
507
+ free (availBlock );
508
+ return err_out_of_memory ;
509
+ }
490
510
availBlock [availBlocks ++ ] = bl ;
491
511
492
512
if (optS )
@@ -507,6 +527,13 @@ static int loadhigh_prepare(void)
507
527
continue ;
508
528
}
509
529
}
530
+ if (allocatedBlocks >= BLOCKMAX ) {
531
+ DOSfree (bl );
532
+ for (i = 0 ; i < availBlocks ; i ++ )
533
+ DOSfree (availBlock [i ]);
534
+ free (availBlock );
535
+ return err_out_of_memory ;
536
+ }
510
537
block [allocatedBlocks ++ ] = bl ; /* no access to this block */
511
538
}
512
539
}
@@ -579,6 +606,10 @@ static int loadfix_prepare(void)
579
606
580
607
dprintf (("loadfix: allocated 0x%04x\n" ,bl ));
581
608
DOSresize (bl , 0x1000 - bl );
609
+ if (allocatedBlocks >= BLOCKMAX ) {
610
+ DOSfree (bl );
611
+ return err_out_of_memory ;
612
+ }
582
613
block [allocatedBlocks ++ ] = bl ;
583
614
}
584
615
0 commit comments