Bug#888782: fp-compiler-3.0.4: fpselect segfaults on arm64
Thanks for reporting this issue. Sorry for not responding earlier, it
must have slipped through the cracks. I'll forward this upstream today.
On Mon, 29 Jan 2018 21:46:22 +0100 Adam Borowski <[hidden email]>
> Package: fp-compiler-3.0.4
> Version: 3.0.4+dfsg-14
> Severity: normal
> The following program segfaults on arm64:
> uses baseunix;
> fpselect(input, nil)
> (Segfault in fpc doesn't give a message, just silently aborts the program
> with return code 216.)
> On amd64 and armhf, all is ok -- the above program waits for something to be
> available on stdin, then completes successfully.
> -- System Information:
> Debian Release: buster/sid
> APT prefers unstable-debug
> APT policy: (500, 'unstable-debug'), (500, 'unstable'), (1, 'experimental')
> Architecture: arm64 (aarch64)
> Kernel: Linux 4.15.0-00183-ga494935d9d25 (SMP w/4 CPU cores; PREEMPT)
> Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE=C.UTF-8 (charmap=UTF-8)
> Shell: /bin/sh linked to /bin/dash
> Init: sysvinit (via /sbin/init)
> Versions of packages fp-compiler-3.0.4 depends on:
> ii binutils 22.214.171.12480122-1
> ii debconf [debconf-2.0] 1.5.65
> ii fp-units-rtl-3.0.4 3.0.4+dfsg-14
> ii libc6 2.26-6
> Versions of packages fp-compiler-3.0.4 recommends:
> ii fp-utils-3.0.4 3.0.4+dfsg-14
> Versions of packages fp-compiler-3.0.4 suggests:
> ii fp-docs-3.0.4 3.0.4+dfsg-14
> -- debconf information:
> fp-compiler/rename_cfg: true
> fp-compiler/windres-select: Select manually
Freepascal upstream noted that this bug was not present in trunk, but didn't research when/how it was fixed, so I decided to do some digging in the source.
It turns out that the "generic syscalls" implementation of fpSelect (used for aarch64) translates the timeout parameter from a timeval (seconds and microseconds) to a timespec (seconds and nanoseconds) before passing it to the "pselect6" system call.
Unfortunately the version of the code in Debian 3.0.4 fails to check if the timeout is nil, dereferences the nil pointer and segfaults.
Using the "blame" tool on an unofficial github mirror of the freepascal source found the commit fixing the issue.