BRepositoryConfig::SetTo(): fix use after deallocation

The strings retrieved from the driver settings were used after
unload_driver_settings(). Use BDriverSettings which also simplifies
things quite a bit.
This commit is contained in:
Ingo Weinhold
2013-07-06 02:13:54 +02:00
parent 30cdb26b5f
commit ee64a0a6db
3 changed files with 15 additions and 34 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
SubDir HAIKU_TOP src build libpackage ; SubDir HAIKU_TOP src build libpackage ;
UsePrivateBuildHeaders kernel package shared ; UsePrivateBuildHeaders kernel package shared storage ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
+3 -1
View File
@@ -4,7 +4,9 @@ UseBuildFeatureHeaders zlib ;
UsePrivateHeaders UsePrivateHeaders
kernel kernel
shared ; shared
storage
;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
+11 -32
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2011, Haiku, Inc. All Rights Reserved. * Copyright 2011-2013, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -19,6 +19,8 @@
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Path.h> #include <Path.h>
#include <DriverSettings.h>
namespace BPackageKit { namespace BPackageKit {
@@ -89,46 +91,23 @@ BRepositoryConfig::SetTo(const BEntry& entry)
fEntry = entry; fEntry = entry;
fInitStatus = B_NO_INIT; fInitStatus = B_NO_INIT;
BFile file(&entry, B_READ_ONLY); entry_ref ref;
status_t result = file.InitCheck(); status_t result = entry.GetRef(&ref);
if (result != B_OK) if (result != B_OK)
return result; return result;
off_t size; BDriverSettings driverSettings;
if ((result = file.GetSize(&size)) != B_OK) result = driverSettings.Load(ref);
if (result != B_OK)
return result; return result;
BString configString; const char* url = driverSettings.GetParameterValue("url");
char* buffer = configString.LockBuffer(size); const char* priorityString = driverSettings.GetParameterValue("priority");
if (buffer == NULL)
return B_NO_MEMORY;
if ((result = file.Read(buffer, size)) < size) {
configString.UnlockBuffer(0);
return (result >= 0) ? B_IO_ERROR : result;
}
buffer[size] = '\0';
configString.UnlockBuffer(size);
void* settingsHandle = parse_driver_settings_string(configString.String());
if (settingsHandle == NULL)
return B_BAD_DATA;
const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
const char* priorityString
= get_driver_parameter(settingsHandle, "priority", NULL, NULL);
unload_driver_settings(settingsHandle);
if (url == NULL || *url == '\0') if (url == NULL || *url == '\0')
return B_BAD_DATA; return B_BAD_DATA;
char name[B_FILE_NAME_LENGTH]; fName = entry.Name();
if ((result = entry.GetName(name)) != B_OK)
return result;
fName = name;
fBaseURL = url; fBaseURL = url;
fPriority = priorityString == NULL fPriority = priorityString == NULL
? kUnsetPriority : atoi(priorityString); ? kUnsetPriority : atoi(priorityString);