Commit Graph

6585 Commits

Author SHA1 Message Date
pho 76248f073a Add a test for kern/58149
aarch64: Cannot return from a signal handler if SP was misaligned when the signal arrived
2024-04-22 07:24:22 +00:00
rillig 6e59c25695 tests/lint: show how to trigger message 207 2024-04-19 20:59:18 +00:00
rillig 4ce516c154 tests/fmtcheck: show that fmtcheck does not support "%2$s" 2024-04-13 14:02:51 +00:00
gson 7809b23883 Require at least 64 MB RAM to run the getrusage_maxrss test case as it
allocates 40 MB and we should leave some for the system, too.
2024-04-12 07:16:50 +00:00
rillig dae6022bba lint: in snprintb, warn about all escaped characters in descriptions 2024-04-12 05:17:48 +00:00
rillig 4ed1e5f144 snprintb.3: provide examples for hexadecimal character escapes
Suggested by uwe@, in reaction to the previous commit, which preferred
octal in the examples. Hexadecimal escapes are more familiar to most
programmers, and the chance of mistaking \x14 for decimal 14 is less
than the chance of mistaking octal \014 for decimal 14.
2024-04-08 21:28:35 +00:00
rillig b5be0901e3 snprintb: reject empty bit descriptions and wrongly placed defaults 2024-04-07 15:20:16 +00:00
rillig 442f4c6c59 snprintb: reject combinations of 'f' with ':' as well as 'F' with '='
These combinations would lead to garbled output.
2024-04-07 12:05:23 +00:00
rillig 864a50a39a snprintb: reject empty descriptions
In cases where the snprintb output is garbled, it is not trustworthy, so
make sure the mistakes in the bitfmt are fixed early.
2024-04-07 10:10:54 +00:00
yamaguchi 6aa7c5ec4b lagg(4) test: Fix typo and old comment 2024-04-05 07:04:17 +00:00
riastradh 561072c7c1 Temporarily make PR t_sp:sigsafe noisier.
This is an attempt to diagnose why it's flaky in the releng testbeds
but not when I run it.  This change will be backed out once we get
new testbed output.
2024-04-04 21:19:25 +00:00
riastradh e5e887ba96 rumpkern/t_sp: Save stdout and stderr to report on failure.
This is not very tidy at the moment, but it's an experiment using the
approach in PR bin/58112, to diagnose why t_sp:sigsafe keeps failing
intermittently.  If this works, perhaps can tidy it up and apply it
to all the other tests that run rump_servers.
2024-04-04 17:27:32 +00:00
christos 0bef817c68 Better output handling (des at FreeBSD) 2024-04-04 16:58:35 +00:00
christos 8fc8182a2b make this work again 2024-04-04 16:57:45 +00:00
riastradh 3e7604f627 i386 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:

- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use forward branches for statically predicted not-taken.
  => val==0 is unlikely in longjmp

PR lib/57946
2024-04-04 00:46:41 +00:00
riastradh df443a3d17 amd64 longjmp: Restore stack first, then signal mask.
Otherwise, a pending signal may be delivered on the wrong stack when
we restore the signal mask.

While here:

- Tidy the code a little bit.
- Sprinkle comments to explain what's going on.
- Use `xorl %eXX,%eXX' instead of `xorq %rXX,%rXX'.
  => Same effect, one byte shorter, breaks dep chain on more uarches.
- Use forward branches for statically predicted not-taken.
  => val==0 is unlikely in longjmp

PR lib/57946
2024-04-04 00:46:30 +00:00
christos fb834229e7 fix the cbrtl/powl test 2024-04-03 01:52:28 +00:00
riastradh ad49149131 elftoolchain: Be consistent about which ELF header files we use.
1. For tools that use elftoolchain: always use elftoolchain's
   elfdefinitions.h.  Don't even think about looking at the host's
   sys/exec_elf.h, which makes no sense and should never happen.

   (ELF tools that don't use elftoolchain, like m68k-elf2coff,
   continue to use nbincludes/sys/exec_elf.h.  But no more nbincludes
   hacks in elftoolchain.)

2. For kernel components (solaris, zfs, dtrace): always use
   sys/exec_elf.h, even in Solaris components via sys/elf.h.
   elfdefinitions.h is not wired up in the kernel build at all.

3. For most userland components that involve libelf: use
   elfdefinitions.h via libelf header files (libelf.h, gelf.h).

   libdtrace in particular requires _all_ R_* reloc type definitions,
   but sys/exec_elf.h brings in only the _current machine's_ R_*
   reloc type definitions.  (While here: Use uintptr_t instead of
   Elf_Addr for pointer-to-integer cast, since Elf_Addr is MD and
   provided only by sys/exec_elf.h, not by elfdefinitions.h.)

   And most userland components using libelf don't rely on any
   properties of the current machine from sys/exec_elf.h, so they can
   use libelf's elfdefinition.h.

   Exceptions:

   - dtrace drti.c relies on link.h -> link_elf.h -> sys/exec_elf.h,
     but it also relies on sys/dtrace.h -> sys/elf.h ->
     elfdefinitions.h like other userland components using sys/elf.h.

   - kdump-ioctl.c uses sys/exec_elf.h directly and sys/dtrace.h ->
     sys/elf.h -> elfdefinitions like other userland components using
     sys/elf.h.

   - t_ptrace_wait.c (via t_ptrace_core_wait.h) uses libelf to parse
     core files, but relies on sys/exec_elf.h for struct
     netbsd_elfcore_procinfo.

   None of these exceptions needs all R_* reloc type definitions, so
   as a workaround, we can just suppress libelf's elfdefinitions.h by
   defining _SYS_ELFDEFINITIONS_H_ and use sys/exec_elf.h in these
   exceptions.

And undo the whole BUILTIN_ELF_HEADERS mistake.  This was:

- half bogus workarounds for missing build_install dependencies in
  tools/Makefile, which are no longer missing now, and
- half futile attempt to use src/sys/sys/exec_elf.h via nbincludes in
  tools involving libelf instead of libelf's elfdefinitions.h, which
  collides.

Longer-term, we may wish to unify sys/exec_elf.h and libelf's
elfdefinitions.h, so we don't have to play these games.

But at least now the games are limited to three .c files (one of
which is generated by Makefile.ioctl-c), rather than haphazardly
applied tree-wide by monstrous kludges in widely used .h files with
broken hackarounds to get the tools build lurching to completion.
2024-04-01 18:33:22 +00:00
rillig 99770e084d tests/snprintb_m: test null-terminated output in error case
While here, clean up the buffer handling for the visualized array
content in case of a failed test.
2024-04-01 09:15:51 +00:00
rillig 0382e641fc lint: in the query about implicit conversions, ignore casts 2024-03-30 19:12:37 +00:00
rillig 370056d3b9 lint: add query for implicit integer-to-floating conversion 2024-03-30 17:23:13 +00:00
rillig def8e1797a lint: do not convert array subscripts from size_t to ptrdiff_t
The C standards do not specify a fixed type for an array subscript, it
just has to be an integer type.  Previously, query 4 fired for the
ubiquitous expression 'ptr[sz]' when sz had type 'size_t'.

The test platform_ilp32_long is unaffected by this change, as the
integer constant 0x80000000 has type 'unsigned int', while size_t is
'unsigned long' on those platforms, and even though the types 'unsigned
int' and 'unsigned long' have the same value space, there's still a
conversion, at least for now.
2024-03-30 17:12:26 +00:00
rillig c6466ed0f7 lint: reword messages about array subscripts to sound more natural 2024-03-30 16:47:44 +00:00
rillig 55398a9a51 lint: fix wording of warning about bit-field initializer 2024-03-29 07:35:45 +00:00
rillig 134116ce30 lint: clean up 2024-03-28 21:04:48 +00:00
rillig 8910413e27 lint: clean up; extend overflow test 2024-03-27 20:09:43 +00:00
rillig e57698da95 lint: don't use 'long' in diagnostics
The size of 'long' differs between 64-bit and 32-bit platforms.
Eliminate this possible platform-dependency.
2024-03-27 19:28:20 +00:00
rillig e6155eab48 t_strptime: fix typo in test description 2024-03-26 21:52:23 +00:00
rillig 216c89c02b lint: fix warnings about loss of accuracy on bit-field operations 2024-03-25 23:39:13 +00:00
rillig 6167e0cc12 tests/lint: demonstrate wrong warnings about lossy bit field operations 2024-03-25 22:46:23 +00:00
rillig 64230f3217 lint: rename snprintb 'directives' to 'conversions'
This aligns the terminology with the snprintf function.
2024-03-25 22:37:43 +00:00
rillig b050579e9d snprintb: mark the end of the buffer if the buffer is too small
This avoids confusion in case the buffer ends with an incomplete number.
2024-03-25 20:39:26 +00:00
martin 56e0726f28 The fetestexcept_trap test case only makes sense on FPUs that implement
exceptions.
2024-03-18 16:33:54 +00:00
riastradh 086a7f840a strptime(3): Exercise some edge cases in the automatic tests.
Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.

PR lib/58041
2024-03-16 00:06:37 +00:00
riastradh f1f68b211d libcrypto: Fix buffer overrun in truncated SHA-512 functions.
Further fallout from the libc/openssl sha2 symbol collision.

PR lib/58039
2024-03-15 18:10:37 +00:00
riastradh 1e152b590b libcrypto: Add some trivial tests for truncated SHA-512 variants.
These should use more of the test vectors from

https://csrc.nist.gov/Projects/Cryptographic-Algorithm-Validation-Program/Secure-Hashing#Testing

but this will do for now to detect the buffer overrun rake we left
lying around for ourselves.

PR lib/58039
2024-03-15 15:32:07 +00:00
rillig 083828859c stat: don't allow numeric formatting flags on strings
Calling snprintf with "%+s" invokes undefined behavior.
2024-03-14 21:17:54 +00:00
rillig 897cdf26ba tests/stat: test the left-aligned and right-aligned 'S' format 2024-03-14 21:00:32 +00:00
rillig 9ca08a6937 tests/lint: ensure that lint correctly decays array parameter types 2024-03-13 06:56:24 +00:00
rillig 9ed4dea22d tests/lint: extend test for previously wrong warning about bit-fields 2024-03-12 20:35:29 +00:00
rillig 9b239cc71c lint: fix warning about loss of conversion for unsigned bit-fields
Since decl.c 1.180 from 2021-05-02.
2024-03-12 07:56:08 +00:00
rillig fc2f5e14be tests/lint: demonstrate wrong warning when comparing a bit-field
Since decl.c 1.180 from 2021-05-02, which allowed arbitrary integer
types to be used as the underlying type for bit-fields in GCC mode.
2024-03-12 07:29:39 +00:00
rillig dd848dec1a lint: add details to the message about integer overflow
Having only the operator was too unspecific to be actionable, so add the
actual numbers and the data type.
2024-03-10 19:45:14 +00:00
rillig bd9743d3db lint: saturate signed integer overflow
In array address calculations, this prevents a 'array subscript cannot
be negative' for large array subscripts.
2024-03-10 16:06:13 +00:00
rillig 08d1bd5c72 lint: fix integer overflow detection
Previously, an unsigned operation that had a negative result went
undetected in a few cases. Now, all results that are not representable
by their type are considered overflows.

The implementation of signed shift-right had been wrong for a few
commits.
2024-03-10 15:49:12 +00:00
rillig 51858eeb3e lint: detect more cases of integer overflow in constant expressions
For unsigned integers, detect when 'a + b' wraps around.
2024-03-10 14:32:30 +00:00
rillig 7d57e750b8 tests/lint: enable test for integer overflow in array index 2024-03-10 10:39:19 +00:00
rillig 25f6e58591 lint: remove wrong warning about overflow in unary '-' for unsigned 2024-03-10 10:31:29 +00:00
rillig 34885a599d lint: fix integer overflow in integer overflow check 2024-03-10 10:15:51 +00:00
rillig 16f849b643 tests/lint: test integer overflow when folding constants
The test is still incomplete, yet it has discovered several bugs that
are worth fixing.
2024-03-10 09:58:30 +00:00