Skip to content

Commit 9cdd24f

Browse files
committed
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
1 parent 4775310 commit 9cdd24f

4 files changed

Lines changed: 9 additions & 1 deletion

File tree

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;

0 commit comments

Comments
 (0)