Skip to content

Commit 62cda74

Browse files
committed
Merge tag 'bootconfig-fixes-v7.0-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull bootconfig fixes from Masami Hiramatsu: - fix off-by-one in xbc_verify_tree() unclosed brace error. This fixes a wrong error place in unclosed brace error message - check bounds before writing in __xbc_open_brace(). This fixes to check the array index before setting array, so that the bootconfig can support 16th-depth nested brace correctly - fix snprintf truncation check in xbc_node_compose_key_after(). This fixes to handle the return value of snprintf() correctly in case of the return value == size - Add bootconfig tests about braces Add test cases for checking error position about unclosed brace and ensuring supporting 16th depth nested braces correctly * tag 'bootconfig-fixes-v7.0-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: bootconfig: Add bootconfig tests about braces lib/bootconfig: fix snprintf truncation check in xbc_node_compose_key_after() lib/bootconfig: check bounds before writing in __xbc_open_brace() lib/bootconfig: fix off-by-one in xbc_verify_tree() unclosed brace error
2 parents 11e8c7e + e2715ea commit 62cda74

6 files changed

Lines changed: 54 additions & 3 deletions

File tree

lib/bootconfig.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,
316316
depth ? "." : "");
317317
if (ret < 0)
318318
return ret;
319-
if (ret > size) {
319+
if (ret >= size) {
320320
size = 0;
321321
} else {
322322
size -= ret;
@@ -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
}
@@ -802,7 +802,7 @@ static int __init xbc_verify_tree(void)
802802

803803
/* Brace closing */
804804
if (brace_index) {
805-
n = &xbc_nodes[open_brace[brace_index]];
805+
n = &xbc_nodes[open_brace[brace_index - 1]];
806806
return xbc_parse_error("Brace is not closed",
807807
xbc_node_get_data(n));
808808
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
foo {
2+
bar {
3+
buz
4+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
key1 {
2+
key2 {
3+
key3 {
4+
key4 {
5+
key5 {
6+
key6 {
7+
key7 {
8+
key8 {
9+
key9 {
10+
key10 {
11+
key11 {
12+
key12 {
13+
key13 {
14+
key14 {
15+
key15 {
16+
key16 {
17+
key17 {
18+
}}}}}}}}}}}}}}}}}
19+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key1.key2.key3.key4.key5.key6.key7.key8.key9.key10.key11.key12.key13.key14.key15.key16;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
key1 {
2+
key2 {
3+
key3 {
4+
key4 {
5+
key5 {
6+
key6 {
7+
key7 {
8+
key8 {
9+
key9 {
10+
key10 {
11+
key11 {
12+
key12 {
13+
key13 {
14+
key14 {
15+
key15 {
16+
key16 {
17+
}}}}}}}}}}}}}}}}
18+

tools/bootconfig/test-bootconfig.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ $BOOTCONF $INITRD > $OUTFILE
171171
xfail grep -q 'val[[:space:]]' $OUTFILE
172172
xpass grep -q 'val2[[:space:]]' $OUTFILE
173173

174+
echo "Showing correct line:column of no closing brace"
175+
cat > $TEMPCONF << EOF
176+
foo {
177+
bar {
178+
}
179+
EOF
180+
$BOOTCONF -a $TEMPCONF $INITRD 2> $OUTFILE
181+
xpass grep -q "1:1" $OUTFILE
182+
174183
echo "=== expected failure cases ==="
175184
for i in samples/bad-* ; do
176185
xfail $BOOTCONF -a $i $INITRD

0 commit comments

Comments
 (0)