From 1182d474227b536299a930a35cfa5d04b23325fb Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 2 Nov 2012 20:43:31 +0000 Subject: [PATCH] - Don't access list nodes after their memory has been freed. - Don't use partition.library functions after we've closed it. - Clear SCSI command structure before use. - Safer extraction of Identify Command strings (even if this command doesn't work because it is an ATA command, not a SCSI command). - Improved debug output. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@45983 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/tools/HDToolBox/gui.c | 11 ++++++----- workbench/tools/HDToolBox/harddisks.c | 18 ++++++++++-------- workbench/tools/HDToolBox/main.c | 5 +++-- workbench/tools/HDToolBox/partitions.c | 10 +++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/workbench/tools/HDToolBox/gui.c b/workbench/tools/HDToolBox/gui.c index fa6ca1cd0e..28ab034a2a 100644 --- a/workbench/tools/HDToolBox/gui.c +++ b/workbench/tools/HDToolBox/gui.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ */ @@ -1405,7 +1405,7 @@ LONG InitListNode(struct ListNode *node, struct ListNode *parent) void UninitListNode(struct ListNode *node) { - struct ListNode *parent; + struct ListNode *parent, *next; D(bug("[HDToolBox] UninitListNode()\n")); @@ -1413,13 +1413,14 @@ void UninitListNode(struct ListNode *node) parent = (struct ListNode *)node->list.lh_Head; while (parent->ln.ln_Succ) { + next = (struct ListNode *)parent->ln.ln_Succ; if (parent->ln.ln_Type == LNT_Parent) { Remove(&parent->ln); FreeMem(parent, sizeof(struct ListNode)); return; } - parent = (struct ListNode *)parent->ln.ln_Succ; + parent = next; } } @@ -1720,8 +1721,8 @@ LONG initGUI(void) app = ApplicationObject, MUIA_Application_Title , "HDToolBox", - MUIA_Application_Version , "$VER: HDToolbox 0.1 (09-Apr-2003)", - MUIA_Application_Copyright , "(c) 1995-2003 by the AROS Development Team", + MUIA_Application_Version , "$VER: HDToolBox 0.2 (2.11.2012)", + MUIA_Application_Copyright , "(c) 1995-2012 AROS Development Team", MUIA_Application_Author , "Bearly, Ogun, Fats and others at AROS", MUIA_Application_Description, "Partition your disks.", MUIA_Application_Base , "HDTOOLBOX", diff --git a/workbench/tools/HDToolBox/harddisks.c b/workbench/tools/HDToolBox/harddisks.c index a5178a5775..e69fd97ddd 100644 --- a/workbench/tools/HDToolBox/harddisks.c +++ b/workbench/tools/HDToolBox/harddisks.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ */ @@ -23,21 +23,23 @@ extern struct GUIGadgets gadgets; void w2strcpy(STRPTR name, UWORD *wstr, ULONG len) { + STRPTR p = name; + while (len) { - *((UWORD *)name) = AROS_BE2WORD(*wstr); - name += sizeof(UWORD); + *((UWORD *)p) = AROS_BE2WORD(*wstr); + p += sizeof(UWORD); len -= 2; wstr++; } - name -= 2; - while ((*name==0) || (*name==' ')) - *name-- = 0; + p -= 2; + while (p >= name && (*p == 0 || *p == ' ')) + *p-- = 0; } BOOL identify(struct IOStdReq *ioreq, STRPTR name) { - struct SCSICmd scsicmd; + struct SCSICmd scsicmd = {0}; UWORD data[256]; UBYTE cmd = 0xEC; /* identify */ @@ -140,7 +142,7 @@ void freeHDList(struct List *list) struct HDNode *node; struct HDNode *next; - D(bug("[HDToolBox] freeHDList()\n")); + D(bug("[HDToolBox] freeHDList(%p)\n", list)); node = (struct HDNode *)list->lh_Head; while (node->root_partition.listnode.ln.ln_Succ) diff --git a/workbench/tools/HDToolBox/main.c b/workbench/tools/HDToolBox/main.c index 1fd0d34052..c4b7d1bcbc 100644 --- a/workbench/tools/HDToolBox/main.c +++ b/workbench/tools/HDToolBox/main.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2008, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ */ @@ -65,13 +65,14 @@ void uninitEnv() D(bug("[HDToolBox] uninitEnv()\n")); deinitGUI(); + freeDeviceList(); + if (PartitionBase) CloseLibrary((struct Library *)PartitionBase); if (GfxBase) CloseLibrary((struct Library *)GfxBase); if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase); - freeDeviceList(); } void waitMessage() diff --git a/workbench/tools/HDToolBox/partitions.c b/workbench/tools/HDToolBox/partitions.c index e04897efec..8e703edaa1 100644 --- a/workbench/tools/HDToolBox/partitions.c +++ b/workbench/tools/HDToolBox/partitions.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2011, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ */ @@ -164,8 +164,7 @@ void findPartitions(struct ListNode *parent, struct HDTBPartition *partition) } /* - * check if partition is active - * (what's the difference between this and automount?) + * check if partition is active (MBR-specific) */ if (getAttrInfo(pn->root->table->pattrlist, PTA_ACTIVE) & PLAM_READ) { @@ -194,10 +193,11 @@ void findPartitions(struct ListNode *parent, struct HDTBPartition *partition) void freePartitionNode(struct HDTBPartition *node) { - D(bug("[HDToolBox] freePartitionNode()\n")); + D(bug("[HDToolBox] freePartitionNode(%p)\n", node)); if (node->table) { + D(bug("[HDToolBox] Freeing sub-table %p\n", node->table)); freePartitionList(&node->listnode.list); freePartitionTable(node); } @@ -211,7 +211,7 @@ void freePartitionList(struct List *list) struct HDTBPartition *node; struct HDTBPartition *next; - D(bug("[HDToolBox] freePartitionList()\n")); + D(bug("[HDToolBox] freePartitionList(%p)\n", list)); node = (struct HDTBPartition *)list->lh_Head; while (node->listnode.ln.ln_Succ) -- 2.11.4.GIT