rockchip-linux / rkdeveloptool

GNU General Public License v2.0
159 stars 91 forks source link

unpackBoot array subscript 20 is outside array bounds of 'char [20]' #40

Closed nullr0ute closed 5 years ago

nullr0ute commented 5 years ago

After applying the fix for #39 there's still build issues, at least with gcc9, with the following error:

g++ -DHAVE_CONFIG_H -I. -I./cfg  -Wall -Werror -Wextra -Wreturn-type -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE -I/usr/include/libusb-1.0    -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -c -o main.o main.cpp
main.cpp: In function 'bool unpackBoot(char*)':
main.cpp:1734:11: error: array subscript 20 is outside array bounds of 'char [20]' [-Werror=array-bounds]
 1734 |  str[len] = 0;
      |  ~~~~~~~~~^~~
main.cpp:1772:7: note: while referencing 'name'
 1772 |  char name[MAX_NAME_LEN];
      |       ^~~~
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:475: main.o] Error 1
rkchrome commented 5 years ago

Can you help try Kever's patch on https://github.com/rockchip-linux/rkdeveloptool/commit/c49bf47e0864d6aa428054ec837c9e3b71dca1ea ?

nullr0ute commented 5 years ago

Looks good.

afaerber commented 5 years ago

That fix no longer assures that the string is null-terminated though. My local fix was to reduce the copy loop to len-1 and use str[len - 1] here.