Skip to contentSkip to conversation

scripts/dtc: Replace 0-length arrays with flexible arrays

PATCH In review Kees Cook 2 participants 5 messages Jan 27, 2023 – Jan 29, 2023 Device tree

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 scripts/dtc: Replace 0-length arrays with flexible arrays

Replace the 0-length array with a C99 flexible array. Seen with GCC 13 under -fstrict-flex-arrays:

In file included from ../lib/fdt_ro.c:2:
../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name':
../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

  319 |                 leaf = strrchr(nameptr, '/');
      |                        ^~~~~~~~~~~~~~~~~~~~~
---
 scripts/dtc/libfdt/fdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/dtc/libfdt/fdt.h +2 -2
index f2e68807f277..0c91aa7f67b5 100644
@@ -35,14 +35,14 @@ struct fdt_reserve_entry {
 
 struct fdt_node_header {
 	fdt32_t tag;
-	char name[0];
+	char name[];
 };
 
 struct fdt_property {
 	fdt32_t tag;
 	fdt32_t len;
 	fdt32_t nameoff;
-	char data[0];
+	char data[];
 };
 
 #endif /* !__ASSEMBLY */
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Kees Cook

Replace the 0-length array with a C99 flexible array. Seen with GCC 13 under -fstrict-flex-arrays:

In file included from ../lib/fdt_ro.c:2:
../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name':
../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

  319 |                 leaf = strrchr(nameptr, '/');
      |                        ^~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
---
 scripts/dtc/libfdt/fdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Changes to dtc/libfdt go to upstream dtc first and then we sync them back.

Rob

author
#2 lore raw
Quoted 19 lines · Rob Herring
Quoted 10 lines · Kees Cook

Replace the 0-length array with a C99 flexible array. Seen with GCC 13 under -fstrict-flex-arrays:

In file included from ../lib/fdt_ro.c:2:
../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name':
../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

  319 |                 leaf = strrchr(nameptr, '/');
      |                        ^~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines
---
 scripts/dtc/libfdt/fdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 1 line

Changes to dtc/libfdt go to upstream dtc first and then we sync them back.

Ah-ha, I've found it: https://github.com/dgibson/dtc

Thanks!

Signature · 1 line
Kees Cook
author
#3 lore raw
Quoted 20 lines · Kees Cook
Quoted 19 lines · Rob Herring
Quoted 17 lines · Kees Cook

Replace the 0-length array with a C99 flexible array. Seen with GCC 13 under -fstrict-flex-arrays:

In file included from ../lib/fdt_ro.c:2:
../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name':
../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

  319 |                 leaf = strrchr(nameptr, '/');
      |                        ^~~~~~~~~~~~~~~~~~~~~
---
 scripts/dtc/libfdt/fdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines
Quoted 1 line

Changes to dtc/libfdt go to upstream dtc first and then we sync them back.

Ah-ha, I've found it: https://github.com/dgibson/dtc

Sent upstream: https://github.com/dgibson/dtc/pull/76

Signature · 1 line
Kees Cook
#4 lore raw
Quoted 22 lines · Kees Cook
Quoted 20 lines · Kees Cook
Quoted 19 lines · Rob Herring
Quoted 17 lines · Kees Cook

Replace the 0-length array with a C99 flexible array. Seen with GCC 13 under -fstrict-flex-arrays:

In file included from ../lib/fdt_ro.c:2:
../lib/../scripts/dtc/libfdt/fdt_ro.c: In function 'fdt_get_name':
../lib/../scripts/dtc/libfdt/fdt_ro.c:319:24: warning: 'strrchr' reading 1 or more bytes from a region of size 0 [-Wstringop-overread]

  319 |                 leaf = strrchr(nameptr, '/');
      |                        ^~~~~~~~~~~~~~~~~~~~~
---
 scripts/dtc/libfdt/fdt.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Changes to dtc/libfdt go to upstream dtc first and then we sync them back.

Ah-ha, I've found it: https://github.com/dgibson/dtc

Sent upstream: https://github.com/dgibson/dtc/pull/76

Maybe David will take that PR, but upstream is here[1]. Patches go to [email protected].

Rob

[1] https://git.kernel.org/pub/scm/utils/dtc/dtc.git