[U-Boot] [PATCH V2] sandbox: terminate os_dirent_ls() result list

From: Stephen Warren swarren@nvidia.com
Each node in the linked-list that os_dirent_ls() returns has its next pointer set only when the next node is created. For the last node in the list, there is no next node, so this never happens, and the next pointer is never initialized. Explicitly initialize the next pointer so that it isn't dangling. Without this, "sb ls" might crash.
Signed-off-by: Stephen Warren swarren@nvidia.com --- v2: Initialize node->next when it's created, rather than deferring it to the end of the loop. This prevents an attempt to initialize node->next if node was never created, since the loop never ran. --- arch/sandbox/cpu/os.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 57d04a45b22b..1c4aa3f9bc4c 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -341,6 +341,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) ret = -ENOMEM; goto done; } + next->next = NULL; strcpy(next->name, entry.d_name); switch (entry.d_type) { case DT_REG:

On 11 June 2014 12:26, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
Each node in the linked-list that os_dirent_ls() returns has its next pointer set only when the next node is created. For the last node in the list, there is no next node, so this never happens, and the next pointer is never initialized. Explicitly initialize the next pointer so that it isn't dangling. Without this, "sb ls" might crash.
Signed-off-by: Stephen Warren swarren@nvidia.com
Acked-by: Simon Glass sjg@chromium.org

On 11 June 2014 22:23, Simon Glass sjg@chromium.org wrote:
On 11 June 2014 12:26, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
Each node in the linked-list that os_dirent_ls() returns has its next pointer set only when the next node is created. For the last node in the list, there is no next node, so this never happens, and the next pointer is never initialized. Explicitly initialize the next pointer so that it isn't dangling. Without this, "sb ls" might crash.
Signed-off-by: Stephen Warren swarren@nvidia.com
Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot-x86/sandbox, thanks!
participants (2)
-
Simon Glass
-
Stephen Warren