lib/mbalign: fix unsigned integer overflow [AddressSanitizer]

This error was reported 155 times.

lib/mbsalign.c:322:18: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
cal: fix signed integer overflow [AddressSanitizer]

misc-utils/cal.c:811:16: runtime error: signed integer overflow:
2147483645 + 536870911 cannot be represented in type 'int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lib: fix crc32 and crc64 interger overflows [AddressSanitizer]

lib/crc32.c:111:11: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

lib/crc64.c:101:12: runtime error: unsigned integer overflow: 0 - 1
cannot be represented in type 'size_t' (aka 'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
fdisk: (sgi) fix unsigned integer overflow [AddressSanitizer]

include/pt-sgi.h:103:7: runtime error: unsigned integer overflow: 0 -
1186450447 cannot be represented in type 'unsigned int'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
strutils: fix unsigned integer overflows [AddressSanitizer]

include/strutils.h:174:10: runtime error: unsigned integer overflow: 0 -
1 cannot be represented in type 'size_t' (aka 'unsigned long')

include/strutils.h:178:6: runtime error: unsigned integer overflow:
18446744073709551615 + 1 cannot be represented in type 'size_t' (aka
'unsigned long')

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/c: define UL_ASAN_BLACKLIST address_sanitizer function attribute

The UL_ASAN_BLACKLIST allows AddressSanitizer to be switched off for
functions that cannot be checked.

Reference: http://dxr.mozilla.org/mozilla-central/source/mfbt/Attributes.h
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
lscpu: blacklist vmware_bdoor() AddressSanitizer check

AddressSanitizer is identifying the __asm__ segment as suspicious.

==1215==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000
(pc 0x0000004ccffd bp 0x7fff9b7184f0 sp 0x7fff9b7184e0 T0)
    #0 0x4ccffc in vmware_bdoor /home/src/util-linux/sys-utils/lscpu.c:660

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
ipcs: fix two data type errors [AddressSanitizer]

==3218==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa577e2b0 at pc 0x4501f9 bp 0x7fffa577e130 sp 0x7fffa577e108
WRITE of size 112 at 0x7fffa577e2b0 thread T0
    #0 0x4501f8 in shmctl /home/users/aadgrand/LLVM/releases/ubuntu/final/llvm.src/projects/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc:2502
    #1 0x48bd13 in ipc_shm_get_info /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcutils.c:157
    #2 0x488884 in do_shm /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:279
    #3 0x4844a8 in main /home/travis/build/kerolasa/lelux-utiliteetit/sys-utils/ipcs.c:175
    #4 0x2afb3f8c176c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
    #5 0x48408c in _start (/home/travis/build/kerolasa/lelux-utiliteetit/ipcs+0x48408c)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
more: blacklist unsigned integer overflow [AddressSanitizer]

The mbrtowc() return values are overflowing by design.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
tests: don't check the current ipcs limits

The ipcs/limit test checks the current kernel limits, but we have no
clue about the current setting, so on on 64bit system it may overflow.

It's better to test for well known limits only. For the random setting
is there ipcs/limit2 test.

Signed-off-by: Karel Zak <kzak@redhat.com>
ipcs: fix shmctl() usage

The function shmctl() has to be called with 'struct shmid_ds', and if
you need 'struct shminfo' then the right way is to cast:

bad way:
  struct shm_info info;

  shmctl(0, SHM_INFO, &info);

right way:
  struct shmid_ds buf;
  struct shm_info *info;

  shmctl(0, SHM_INFO, &buf);
  info = (struct shm_info *) &buf);

The patch also fixes bug in ipc_shm_get_limits() where is missing
lim->shmmax in code based on shmctl().

Signed-off-by: Karel Zak <kzak@redhat.com>