Skip to content

Commit

Permalink
AMIGAOS4: Fix NULL access
Browse files Browse the repository at this point in the history
  • Loading branch information
raziel- authored and bluegr committed Oct 8, 2019
1 parent 4620843 commit bfc296b
Showing 1 changed file with 37 additions and 24 deletions.
61 changes: 37 additions & 24 deletions backends/fs/amigaos4/amigaos4-fs.cpp
Expand Up @@ -62,13 +62,21 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode() {
_bIsDirectory = true; _bIsDirectory = true;
_sPath = ""; _sPath = "";
_pFileLock = 0; _pFileLock = 0;
_nProt = 0; // Protection is ignored for the root volume _nProt = 0; // Protection is ignored for the root volume.
LEAVE(); LEAVE();
} }


AmigaOSFilesystemNode::AmigaOSFilesystemNode(const Common::String &p) { AmigaOSFilesystemNode::AmigaOSFilesystemNode(const Common::String &p) {
ENTER(); ENTER();


// We need to explicitely open dos.library and it's IDOS interface.
// Otherwise we'll hit an IDOS NULL pointer after compiling a shared
// binary with (shared) plugins.
// The hit will happen on loading a game from any engine, if more
// than one engine/plugin is available.
DOSBase=IExec->OpenLibrary("dos.library",0);
IDOS = (struct DOSIFace *)IExec->GetInterface(DOSBase, "main", 1, NULL);

int offset = p.size(); int offset = p.size();


//assert(offset > 0); //assert(offset > 0);
Expand All @@ -84,7 +92,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const Common::String &p) {
_bIsDirectory = false; _bIsDirectory = false;
_bIsValid = false; _bIsValid = false;


// Check whether the node exists and if it's a directory // Check whether the node exists and if it's a directory.
struct ExamineData * pExd = IDOS->ExamineObjectTags(EX_StringNameInput,_sPath.c_str(),TAG_END); struct ExamineData * pExd = IDOS->ExamineObjectTags(EX_StringNameInput,_sPath.c_str(),TAG_END);
if (pExd) { if (pExd) {
_nProt = pExd->Protection; _nProt = pExd->Protection;
Expand All @@ -93,7 +101,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const Common::String &p) {
_pFileLock = IDOS->Lock((CONST_STRPTR)_sPath.c_str(), SHARED_LOCK); _pFileLock = IDOS->Lock((CONST_STRPTR)_sPath.c_str(), SHARED_LOCK);
_bIsValid = (_pFileLock != 0); _bIsValid = (_pFileLock != 0);


// Add a trailing slash if needed // Add a trailing slash if needed.
const char c = _sPath.lastChar(); const char c = _sPath.lastChar();
if (c != '/' && c != ':') if (c != '/' && c != ':')
_sPath += '/'; _sPath += '/';
Expand All @@ -105,6 +113,10 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(const Common::String &p) {
IDOS->FreeDosObject(DOS_EXAMINEDATA, pExd); IDOS->FreeDosObject(DOS_EXAMINEDATA, pExd);
} }


// Close dos.library and it's IDOS interface again.
IExec->DropInterface((struct Interface *)IDOS);
IExec->CloseLibrary(DOSBase);

LEAVE(); LEAVE();
} }


Expand Down Expand Up @@ -161,7 +173,7 @@ AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayNam
LEAVE(); LEAVE();
} }


// We need the custom copy constructor because of DupLock() // We need the custom copy constructor because of DupLock().
AmigaOSFilesystemNode::AmigaOSFilesystemNode(const AmigaOSFilesystemNode& node) AmigaOSFilesystemNode::AmigaOSFilesystemNode(const AmigaOSFilesystemNode& node)
: AbstractFSNode() { : AbstractFSNode() {
ENTER(); ENTER();
Expand Down Expand Up @@ -237,9 +249,6 @@ bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, b
ENTER(); ENTER();
bool ret = false; bool ret = false;


// TODO: Honor the hidden flag
// There is no such thing as a hidden flag in AmigaOS...

if (!_bIsValid) { if (!_bIsValid) {
debug(6, "Invalid node"); debug(6, "Invalid node");
LEAVE(); LEAVE();
Expand Down Expand Up @@ -343,9 +352,9 @@ bool AmigaOSFilesystemNode::isReadable() const {
if (!_bIsValid) if (!_bIsValid)
return false; return false;


// Regular RWED protection flags are low-active or inverted, thus the negation. // Regular RWED protection flags are low-active or inverted,
// Moreover, a pseudo root filesystem is readable whatever the // thus the negation. Moreover, a pseudo root filesystem is
// protection says. // readable whatever the protection says.
bool readable = !(_nProt & EXDF_OTR_READ) || isRootNode(); bool readable = !(_nProt & EXDF_OTR_READ) || isRootNode();


return readable; return readable;
Expand All @@ -355,9 +364,10 @@ bool AmigaOSFilesystemNode::isWritable() const {
if (!_bIsValid) if (!_bIsValid)
return false; return false;


// Regular RWED protection flags are low-active or inverted, thus the negation. // Regular RWED protection flags are low-active or inverted,
// Moreover, a pseudo root filesystem is never writable whatever // thus the negation. Moreover, a pseudo root filesystem is
// the protection says (Because of it's pseudo nature). // never writable whatever the protection says.
// (Because of it's pseudo nature).
bool writable = !(_nProt & EXDF_OTR_WRITE) && !isRootNode(); bool writable = !(_nProt & EXDF_OTR_WRITE) && !isRootNode();


return writable; return writable;
Expand Down Expand Up @@ -385,18 +395,21 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const {
dosList->dol_Port) { dosList->dol_Port) {


// The original line was // The original line was
//if (dosList->dol_Type == DLT_VOLUME && //
//dosList->dol_Name && // if (dosList->dol_Type == DLT_VOLUME &&
//dosList->dol_Task) { // dosList->dol_Name &&
// which errored using SDK 53.24 with a 'struct dosList' has no member called 'dol_Task' // dosList->dol_Task) {
// The reason for that was that //
// 1) dol_Task wasn't a task pointer, it is a message port instead // which errored using SDK 53.24 with a
// 2) It was redefined to be dol_Port in dos/obsolete.h in afore mentioned SDK // 'struct dosList' has no member called 'dol_Task'

// The reason for that was, that
// Copy name to buffer // 1) dol_Task wasn't a task pointer, it is a message port instead.
// 2) it was redefined to be dol_Port in dos/obsolete.h in aforementioned SDK.

// Copy name to buffer.
IDOS->CopyStringBSTRToC(dosList->dol_Name, buffer, MAXPATHLEN); IDOS->CopyStringBSTRToC(dosList->dol_Name, buffer, MAXPATHLEN);


// Volume name + '\0' // Volume name + '\0'.
char *volName = new char [strlen(buffer) + 1]; char *volName = new char [strlen(buffer) + 1];


strcpy(volName, buffer); strcpy(volName, buffer);
Expand All @@ -408,7 +421,7 @@ AbstractFSList AmigaOSFilesystemNode::listVolumes() const {


char *devName = new char [MAXPATHLEN]; char *devName = new char [MAXPATHLEN];


// Find device name // Find device name.
IDOS->DevNameFromLock(volumeLock, devName, MAXPATHLEN, DN_DEVICEONLY); IDOS->DevNameFromLock(volumeLock, devName, MAXPATHLEN, DN_DEVICEONLY);


sprintf(buffer, "%s (%s)", volName, devName); sprintf(buffer, "%s (%s)", volName, devName);
Expand Down

0 comments on commit bfc296b

Please sign in to comment.