get_next_loaded_module_name() now uses the same (inefficient) mechanism read_next_module_name() is using thanks to Siarzhuk - the previous mechanism was completely unsafe.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21316 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1245,30 +1245,27 @@ get_next_loaded_module_name(uint32 *_cookie, char *buffer, size_t *_bufferSize)
|
|||||||
if (_cookie == NULL || buffer == NULL || _bufferSize == NULL)
|
if (_cookie == NULL || buffer == NULL || _bufferSize == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
hash_iterator *iterator = (hash_iterator *)*_cookie;
|
status_t status = B_ENTRY_NOT_FOUND;
|
||||||
status_t status;
|
uint32 offset = *_cookie;
|
||||||
|
|
||||||
if (iterator == NULL) {
|
|
||||||
iterator = hash_open(sModulesHash, NULL);
|
|
||||||
if (iterator == NULL)
|
|
||||||
return B_NO_MEMORY;
|
|
||||||
|
|
||||||
*(hash_iterator **)_cookie = iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
recursive_lock_lock(&sModulesLock);
|
recursive_lock_lock(&sModulesLock);
|
||||||
|
|
||||||
// TODO: this is completely unsafe!!!
|
|
||||||
|
|
||||||
struct module *module = (struct module *)hash_next(sModulesHash, iterator);
|
hash_iterator iterator;
|
||||||
if (module != NULL) {
|
hash_open(sModulesHash, &iterator);
|
||||||
*_bufferSize = strlcpy(buffer, module->name, *_bufferSize);
|
struct module *module = (struct module *)hash_next(sModulesHash,
|
||||||
status = B_OK;
|
&iterator);
|
||||||
} else {
|
|
||||||
hash_close(sModulesHash, iterator, true);
|
for (uint32 i = 0; module != NULL; i++) {
|
||||||
status = B_ENTRY_NOT_FOUND;
|
if (i >= offset) {
|
||||||
|
*_bufferSize = strlcpy(buffer, module->name, *_bufferSize);
|
||||||
|
*_cookie = i + 1;
|
||||||
|
status = B_OK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
module = (struct module *)hash_next(sModulesHash, &iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash_close(sModulesHash, &iterator, false);
|
||||||
recursive_lock_unlock(&sModulesLock);
|
recursive_lock_unlock(&sModulesLock);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
Reference in New Issue
Block a user