Skip to content

Commit 9474bbf

Browse files
authored
exec, dos: assorted bug fixes (#148)
* dos: buffer-overrun and resource-leak fixes - fgets: bail early on zero-length buffer, decrement once - getvar: close file handle on the size-lookup failure path - runhandler: UnLock dir on the LoadSeg success path - splitname: bail early on zero-size buffer * exec: free-list, allocator, task and memory bugfixes - switch HANDLE_MANAGED_MEM tests from #ifdef to #if (the macro is defined as 0 when disabled, so #ifdef was wrong) - memory: free-list consistency, MEMF_MANAGED tests, pool fixes - memory_nommu: round byteSize up to MEMCHUNK_TOTAL in AllocMem - newaddtask: pass MemEntry list head correctly - prepareexecbase: respect "nomungwall" arg, OR-in stacksnoop flag instead of clobbering, fix Preparation debug print - remtask: Disable around list removal to protect against interrupt-level Signal moving the task between lists - signal: priority comparison uses strict greater-than for preemption; corrected debug-print arguments
1 parent a998f9e commit 9474bbf

18 files changed

Lines changed: 61 additions & 39 deletions

rom/dos/fgets.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
ULONG len = 0;
5555
LONG c;
5656

57-
buflen--;
57+
if(!buflen)
58+
return NULL;
59+
60+
buflen--;
5861

5962
do
6063
{

rom/dos/getvar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ static LONG getvar_from(const char *name, const char *volume, STRPTR buffer, LON
237237
{
238238
D(bug("GetVar: can't find size\n"));
239239

240+
Close(file);
240241
return -1;
241242
}
242243

rom/dos/runhandler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct MsgPort *RunHandler(struct DeviceNode *deviceNode, const char *path, stru
7373
D(bug("[RunHandler] LoadSeg(\"L:%s\")\n", cp));
7474
deviceNode->dn_SegList = LoadSeg(cp);
7575
CurrentDir(olddir);
76+
UnLock(dir);
7677
}
7778
}
7879
}

rom/dos/splitname.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
{
7070
AROS_LIBFUNC_INIT
7171

72+
if(!size)
73+
return -1;
74+
7275
size --;
7376

7477
name += oldpos;

rom/exec/allocate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
{
8585
AROS_LIBFUNC_INIT
8686

87-
#ifdef HANDLE_MANAGED_MEM
87+
#if HANDLE_MANAGED_MEM
8888
if ((freeList->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(freeList))
8989
{
9090
struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;

rom/exec/allocpooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
if(!memSize)
7676
return NULL;
7777

78-
#ifdef HANDLE_MANAGED_MEM
78+
#if HANDLE_MANAGED_MEM
7979
if (IsManagedMem(mhe))
8080
{
8181
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;

rom/exec/allocvecpooled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
/* 0-sized allocation results in returning NULL (API guarantee) */
5757
if(!memSize)
5858
return NULL;
59-
#ifdef HANDLE_MANAGED_MEM
59+
#if HANDLE_MANAGED_MEM
6060
if (IsManagedMem(mhe))
6161
{
6262
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;

rom/exec/createpool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
* If the pool is in managed memory, don't bother any further setup. The
140140
* pool should do the rest self.
141141
*/
142-
#ifdef HANDLE_MANAGED_MEM
142+
#if HANDLE_MANAGED_MEM
143143
if (IsManagedMem(firstPuddle))
144144
{
145145
D(bug("Managed pool\n");)

rom/exec/deallocate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
{
5959
AROS_LIBFUNC_INIT
6060

61-
#ifdef HANDLE_MANAGED_MEM
61+
#if HANDLE_MANAGED_MEM
6262
if ((freeList->mh_Node.ln_Type == NT_MEMORY) && IsManagedMem(freeList))
6363
{
6464
struct MemHeaderExt *mhe = (struct MemHeaderExt *)freeList;

rom/exec/deletepool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{
6262
struct TraceLocation tp = CURRENT_LOCATION("DeletePool");
6363

64-
#ifdef HANDLE_MANAGED_MEM
64+
#if HANDLE_MANAGED_MEM
6565
if (IsManagedMem(poolHeader))
6666
{
6767
/* Do nothing, everything is handled in FreeMemHeader */

0 commit comments

Comments
 (0)