Project

General

Profile

Bug #6173

GCC12: error: array subscript 1 is outside array bounds

Added by Dirk Diggler 8 months ago. Updated 2 months ago.

Status:
Fixed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
2022-05-27
Due date:
% Done:

0%

Estimated time:
Found in version:
latest snapshot
Affected Versions:

Description

See: https://aur.archlinux.org/packages/tvheadend-git

In file included from src/tcp.c:32:
In function 'ip_check_is_any_v6',
inlined from 'ip_check_is_any' at src/tcp.h:109:46,
inlined from 'ip_check_is_local_address' at src/tcp.c:89:17:
src/tcp.h:104:57: error: array subscript 1 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
104 | { return ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[0] == ((uint64_t *)(&in6addr_any.s6_addr))[0] && | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:107:19: note: at offset 8 into object 'address' of size 8
107 | static inline int ip_check_is_any(const struct sockaddr_storage *address) | ^~~~~~~~~~~~~
In function 'ip_check_is_any_v6',
inlined from 'ip_check_is_any' at src/tcp.h:109:46,
inlined from 'ip_check_is_local_address' at src/tcp.c:89:17:
src/tcp.h:105:57: error: array subscript 2 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
105 | ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[1] == ((uint64_t *)(&in6addr_any.s6_addr))[1]; } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:107:19: note: at offset 16 into object 'address' of size 8
107 | static inline int ip_check_is_any(const struct sockaddr_storage *address) | ^~~~~~~~~~~~~
In function 'ip_check_equal_v6',
inlined from 'ip_check_equal' at src/tcp.h:78:42,
inlined from 'ip_check_is_local_address' at src/tcp.c:96:26:
src/tcp.h:71:53: error: array subscript 1 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
71 | { return ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[0] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[0] && | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:74:19: note: at offset 8 into object 'a' of size 8
74 | static inline int ip_check_equal | ^~~~~~~~~~~~
In function 'ip_check_equal_v6',
inlined from 'ip_check_equal' at src/tcp.h:78:42,
inlined from 'ip_check_is_local_address' at src/tcp.c:96:26:
src/tcp.h:71:99: error: array subscript 1 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
71 | { return ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[0] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[0] && | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:74:19: note: at offset 8 into object 'b' of size 8
74 | static inline int ip_check_equal | ^~~~~~~~~~~~
In function 'ip_check_equal_v6',
inlined from 'ip_check_equal' at src/tcp.h:78:42,
inlined from 'ip_check_is_local_address' at src/tcp.c:96:26:
src/tcp.h:72:53: error: array subscript 2 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
72 | ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[1] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[1]; } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:74:19: note: at offset 16 into object 'a' of size 8
74 | static inline int ip_check_equal | ^~~~~~~~~~~~
In function 'ip_check_equal_v6',
inlined from 'ip_check_equal' at src/tcp.h:78:42,
inlined from 'ip_check_is_local_address' at src/tcp.c:96:26:
src/tcp.h:72:99: error: array subscript 2 is outside array bounds of 'const struct sockaddr_storage0' [-Werror=array-bounds]
72 | ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[1] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[1]; } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function 'ip_check_is_local_address':
src/tcp.h:74:19: note: at offset 16 into object 'b' of size 8
74 | static inline int ip_check_equal

History

#1

Updated by Flole Systems 8 months ago

  • Status changed from New to Invalid

You're using an unofficial/modified build. Contact the maintainer for support.

#2

Updated by Dirk Diggler 8 months ago

Flole Systems wrote:

You're using an unofficial/modified build. Contact the maintainer for support.

Hey, not so fast. I get the same error when compiling the current github source!

#3

Updated by Flole Systems 8 months ago

Then feel free to update this so it's a proper bug report (including which OS and compiler is used and steps to reproduce) then it can be re-opened, but don't expect anyone to work on it as it's building perfectly fine on 24 different systems. If you provide a PR though it will be reviewed and merged eventually.

#4

Updated by Dirk Diggler 8 months ago

Operating System: Arch Linux
Kernel: Linux 5.17.9-arch1-1
Architecture: x86-64

gcc (GCC) 12.1.0

Steps: ./configure, make

#5

Updated by Dirk Diggler 8 months ago

Hey, compiler version was a good hint. I installed older GCC 11 version, which works.
So i don't know if tvheadend code has to be fixed for GCC 12?

#6

Updated by Flole Systems 8 months ago

  • Subject changed from error: array subscript 1 is outside array bounds to GCC12: error: array subscript 1 is outside array bounds
  • Status changed from Invalid to New
#7

Updated by Pim Zandbergen 8 months ago

Fedora 36 switched to GCC 12 too.

#8

Updated by Volker Schmidt 6 months ago

Found a wuerg-around (err, german-IT-slang) - a work around for GCC 12.

Add this for your additions to CFLAGS (PKGBUILD / environment / Makefile):

export CFLAGS="$CFLAGS -Wno-error=array-bounds -Wno-error=address"

tvheadend now builds.

#9

Updated by Flole Systems 5 months ago

That is not a solution though, there are several things wrong with that code. For example in the ip_check_equal_v6 (and probably in others aswell) there is a pointer to a pointer which is then casted to an uint64_t* and then offset 1 of that is accessed. It will never work like this, and basically same thing for IPv4. Someone needs to go through all usages and figure out where it needs to be changed so that always a pointer is passed and the & needs to be removed from the IP_AS_V* aswell.

Also for IPv6 there is a strict aliasing violation, even with those fixes the comparison like that is undefined behaviour.

#10

Updated by Georg Schukat 4 months ago

OS: openSuse Tumbleweed (rolling release)
Kernel: 5.19.13-1-default
gcc: (SUSE Linux) 12.2.1 20220830

config: (if these were enabled make would run into other issues)

./configure  --disable-tvhcsa  --disable-libopus

same make fail:

CC              src/tvhvfs.o
CC              src/access.o
CC              src/tcp.o
In file included from src/tcp.c:32:
In function ‘ip_check_is_any_v6’,
    inlined from ‘ip_check_is_any’ at src/tcp.h:109:46,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:89:17:
src/tcp.h:104:57: error: array subscript 1 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
  104 |   { return ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[0] == ((uint64_t *)(&in6addr_any.s6_addr))[0] &&
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:107:19: note: at offset 8 into object ‘address’ of size 8
  107 | static inline int ip_check_is_any(const struct sockaddr_storage *address)
      |                   ^~~~~~~~~~~~~~~
In function ‘ip_check_is_any_v6’,
    inlined from ‘ip_check_is_any’ at src/tcp.h:109:46,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:89:17:
src/tcp.h:105:57: error: array subscript 2 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
  105 |            ((uint64_t *)IP_AS_V6(address, addr).s6_addr)[1] == ((uint64_t *)(&in6addr_any.s6_addr))[1]; }
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:107:19: note: at offset 16 into object ‘address’ of size 8
  107 | static inline int ip_check_is_any(const struct sockaddr_storage *address)
      |                   ^~~~~~~~~~~~~~~
In function ‘ip_check_equal_v6’,
    inlined from ‘ip_check_equal’ at src/tcp.h:78:42,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:96:26:
src/tcp.h:71:53: error: array subscript 1 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
   71 |     { return ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[0] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[0] &&
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:74:19: note: at offset 8 into object ‘a’ of size 8
   74 | static inline int ip_check_equal
      |                   ^~~~~~~~~~~~~~
In function ‘ip_check_equal_v6’,
    inlined from ‘ip_check_equal’ at src/tcp.h:78:42,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:96:26:
src/tcp.h:71:99: error: array subscript 1 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
   71 |     { return ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[0] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[0] &&
      |                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:74:19: note: at offset 8 into object ‘b’ of size 8
   74 | static inline int ip_check_equal
      |                   ^~~~~~~~~~~~~~
In function ‘ip_check_equal_v6’,
    inlined from ‘ip_check_equal’ at src/tcp.h:78:42,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:96:26:
src/tcp.h:72:53: error: array subscript 2 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
   72 |              ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[1] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[1]; }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:74:19: note: at offset 16 into object ‘a’ of size 8
   74 | static inline int ip_check_equal
      |                   ^~~~~~~~~~~~~~
In function ‘ip_check_equal_v6’,
    inlined from ‘ip_check_equal’ at src/tcp.h:78:42,
    inlined from ‘ip_check_is_local_address’ at src/tcp.c:96:26:
src/tcp.h:72:99: error: array subscript 2 is outside array bounds of ‘const struct sockaddr_storage[0]’ [-Werror=array-bounds]
   72 |              ((uint64_t *)IP_AS_V6(a, addr).s6_addr)[1] == ((uint64_t *)IP_AS_V6(b, addr).s6_addr)[1]; }
      |                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:74:19: note: at offset 16 into object ‘b’ of size 8
   74 | static inline int ip_check_equal
      |                   ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:718: /A/DEVE/tvheadend/build.linux/src/tcp.o] Fehler 1
make[1]: Verzeichnis „/A/DEVE/tvheadend“ wird verlassen
make: *** [Makefile:110: ffmpeg_all] Fehler 2

#11

Updated by Georg Schukat 4 months ago

Volker Schmidt wrote:

Found a wuerg-around (err, german-IT-slang) - a work around for GCC 12.
Add this for your additions to CFLAGS (PKGBUILD / environment / Makefile):

export CFLAGS="$CFLAGS -Wno-error=array-bounds -Wno-error=address"

tvheadend now builds.

worked for me as well

#12

Updated by Markus Bonet 3 months ago

Is there any additional information needed to work on this bug?

#13

Updated by Flole Systems 3 months ago

What's needed are people who work on this bug.

#14

Updated by Flole Systems 3 months ago

  • Status changed from New to Fixed

DonKult was kind enough to provide a fix on GitHub.

#15

Updated by B C 3 months ago

since that fix I get the following error on gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)

CC src/htsmsg_binary.o
In file included from src/tcp.c:32:
In function ‘ip_check_is_any_v6’,
inlined from ‘ip_check_is_any’ at src/tcp.h:109:46,
inlined from ‘ip_check_is_local_address’ at src/tcp.c:89:17:
src/tcp.h:105:12: error: ‘__builtin_memcmp_eq’ specified bound 16 exceeds source size 8 [-Werror=stringop-overread]
105 | { return memcmp(IP_AS_V6(address, addr).s6_addr, in6addr_any.s6_addr, sizeof(in6addr_any.s6_addr)) == 0; } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:107:19: note: source object declared here
107 | static inline int ip_check_is_any(const struct sockaddr_storage *address) | ^~~~~~~~~~~~~
In file included from src/tcp.c:32:
In function ‘ip_check_equal_v6’,
inlined from ‘ip_check_equal’ at src/tcp.h:77:42,
inlined from ‘ip_check_is_local_address’ at src/tcp.c:96:26:
src/tcp.h:71:14: error: ‘__builtin_memcmp_eq’ specified bound 16 exceeds source size 8 [-Werror=stringop-overread]
71 | { return memcmp(IP_AS_V6(a, addr).s6_addr, IP_AS_V6(b, addr).s6_addr, sizeof(IP_AS_V6(a, addr).s6_addr)) == 0; } | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/tcp.h: In function ‘ip_check_is_local_address’:
src/tcp.h:73:19: note: source object declared here
73 | static inline int ip_check_equal | ^~~~~~~~~~~~
CC src/htsmsg_binary2.o
CC src/htsmsg_json.o
cc1: all warnings being treated as errors

#16

Updated by Jonas Lang 2 months ago

Same as #15 on Ubuntu 22.04 LTS x86_64 building with GCC 11.3.0

Also available in: Atom PDF