From 8d1317e1b6100f7bdec1459ad2b7717a7145ebed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 3 Jun 2007 23:09:59 +0000 Subject: [PATCH] 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 --- src/system/kernel/module.cpp | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/system/kernel/module.cpp b/src/system/kernel/module.cpp index 12c70d236a..bf509d90a2 100644 --- a/src/system/kernel/module.cpp +++ b/src/system/kernel/module.cpp @@ -1245,30 +1245,27 @@ get_next_loaded_module_name(uint32 *_cookie, char *buffer, size_t *_bufferSize) if (_cookie == NULL || buffer == NULL || _bufferSize == NULL) return B_BAD_VALUE; - hash_iterator *iterator = (hash_iterator *)*_cookie; - status_t status; - - if (iterator == NULL) { - iterator = hash_open(sModulesHash, NULL); - if (iterator == NULL) - return B_NO_MEMORY; - - *(hash_iterator **)_cookie = iterator; - } + status_t status = B_ENTRY_NOT_FOUND; + uint32 offset = *_cookie; recursive_lock_lock(&sModulesLock); - - // TODO: this is completely unsafe!!! - struct module *module = (struct module *)hash_next(sModulesHash, iterator); - if (module != NULL) { - *_bufferSize = strlcpy(buffer, module->name, *_bufferSize); - status = B_OK; - } else { - hash_close(sModulesHash, iterator, true); - status = B_ENTRY_NOT_FOUND; + hash_iterator iterator; + hash_open(sModulesHash, &iterator); + struct module *module = (struct module *)hash_next(sModulesHash, + &iterator); + + for (uint32 i = 0; module != NULL; i++) { + 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); return status;