MinimSecure / unum-sdk

Unum agent source code, tools, and documentation
https://www.minim.co
Apache License 2.0
30 stars 15 forks source link

Compile error util/dns.c Werror=array-bounds #108

Open cptnmidnight opened 3 years ago

cptnmidnight commented 3 years ago

System: Linux mint 19.1 Ubuntu bionic make 4.1 gcc 7.5.0 openwrt git master unum git https://github.com/MinimSecure/minim-openwrt-feed.git

Compile stops with:

`util/dns.c: In function 'dns_so_check.part.57': util/dns.c:6528:17: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds] so->query->data[-2] = 0xff & (so->query->end >> 8);


util/dns.c:6529:17: error: array subscript -1 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
  so->query->data[-1] = 0xff & (so->query->end >> 0);
  ~~~~~~~~~~~~~~~^~~~
util/dns.c:6531:9: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
  qsrc = &so->query->data[-2] + so->qout;
         ^~~~~~~~~~~~~~~~~~~~
util/dns.c:6557:10: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
   asrc = &so->answer->data[-2];
          ^~~~~~~~~~~~~~~~~~~~~
util/dns.c:6568:18: error: array subscript -2 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
    alen = ((0xff & so->answer->data[-2]) << 8)
            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
util/dns.c:6569:42: error: array subscript -1 is below array bounds of 'unsigned char[1]' [-Werror=array-bounds]
         | ((0xff & so->answer->data[-1]) << 0);
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
cc1: all warnings being treated as errors
Makefile:96: recipe for target 'util/dns.o' failed
make[4]: *** [util/dns.o] Error 1
make[4]: Leaving directory '/home/doc/router/openwrt/build_dir/target-mips_24kc_musl/unum-2020.1.0/src/unum'
Makefile:107: recipe for target '/home/doc/router/openwrt/build_dir/target-mips_24kc_musl/unum-2020.1.0/.built' failed
make[3]: *** [/home/doc/router/openwrt/build_dir/target-mips_24kc_musl/unum-2020.1.0/.built] Error 2
make[3]: Leaving directory '/home/doc/router/openwrt/feeds/minim/unum'
time: package/feeds/minim/unum/compile#15.47#5.48#27.12
    ERROR: package/feeds/minim/unum failed to build.
package/Makefile:112: recipe for target 'package/feeds/minim/unum/compile' failed
make[2]: *** [package/feeds/minim/unum/compile] Error 1
make[2]: Leaving directory '/home/doc/router/openwrt'
package/Makefile:108: recipe for target '/home/doc/router/openwrt/staging_dir/target-mips_24kc_musl/stamp/.package_compile' failed
`

[dotconfig.txt](https://github.com/MinimSecure/unum-sdk/files/6058425/dotconfig.txt)
raymondjclark commented 3 years ago

I have run into the same problem. Something must have changed. This code appears to have come from https://github.com/wahern/dns/blob/master/src/dns.c and has not been touched for 4 years.

tyler-sommer commented 3 years ago

Thanks for opening this.

We've made a fix in https://github.com/MinimSecure/unum-sdk/commit/8ad9b8b0fc967f4e5ef83e28bb467511d84c2f7d related to this. Could you please try pulling the latest master and see if the error persists?

edited to add: You will need to modify the unum Makefile line 22 in the minim-openwrt-feed to reference the commit 8ad9b8b0fc967f4e5ef83e28bb467511d84c2f7d

tyler-sommer commented 3 years ago

Following up on this. I tried building this myself but it seems that because we've removed support for openwrt_generic, there is no way to produce a properly functioning build using the minim-openwrt-feed.

It seems that going forward, the instructions for lede_generic should be used which involves cloning our fork of the openwrt sources called violetatrium/lede and creating a specific hardware kind for your device. There's additional info about doing that in the README.txt in the lede project repo.

Sorry about the confusion on this one. I'm going to archive the minim-openwrt-feed project and update the README there with this guidance. Please reach out if you have any questions. Thanks again!

raymondjclark commented 3 years ago

Now getting these errors:

util/dns.c:6523:2: error: array subscript 4294967294 is above array bounds of 'unsigned char[1]' [-Werror=array-bounds] (so->query->data - 2) = 0xff & (so->query->end >> 8); ^~~~~~ util/dns.c:6524:2: error: array subscript 4294967295 is above array bounds of 'unsigned char[1]' [-Werror=array-bounds] (so->query->data - 1) = 0xff & (so->query->end >> 0); ^~~~~~ util/dns.c:6563:18: error: array subscript 4294967294 is above array bounds of 'unsigned char[1]' [-Werror=array-bounds] alen = ((0xff & *(so->answer->data - 2)) << 8)


util/dns.c:6564:45: error: array subscript 4294967295 is above array bounds of 'unsigned char[1]' [-Werror=array-bounds]
         | ((0xff & *(so->answer->data - 1)) << 0);
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
dob71 commented 3 years ago

Bummer, I was hoping just removing subscripts would be enough. Unfortunately it's hard to chase this down without spinning up the environment where this error can be reproduced. You can try to fix it yourself and submit PR or diff for us to pull in. IMO it should be resolvable by making the compiler treat "data" as a plain pointer (maybe just casting the "...->data" to "unsigned char *" before trying to offset it).