Skip to content

Commit 560f763

Browse files
techyguyperplexablemhiramat
authored andcommitted
lib/bootconfig: check bounds before writing in __xbc_open_brace()
The bounds check for brace_index happens after the array write. While the current call pattern prevents an actual out-of-bounds access (the previous call would have returned an error), the write-before-check pattern is fragile and would become a real out-of-bounds write if the error return were ever not propagated. Move the bounds check before the array write so the function is self-contained and safe regardless of caller behavior. Link: https://lore.kernel.org/all/[email protected]/ Fixes: ead1e19 ("lib/bootconfig: Fix a bug of breaking existing tree nodes") Cc: [email protected] Signed-off-by: Josh Law <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 39ebc8d commit 560f763

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/bootconfig.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ static char *skip_spaces_until_newline(char *p)
532532
static int __init __xbc_open_brace(char *p)
533533
{
534534
/* Push the last key as open brace */
535-
open_brace[brace_index++] = xbc_node_index(last_parent);
536535
if (brace_index >= XBC_DEPTH_MAX)
537536
return xbc_parse_error("Exceed max depth of braces", p);
537+
open_brace[brace_index++] = xbc_node_index(last_parent);
538538

539539
return 0;
540540
}

0 commit comments

Comments
 (0)