Tags 888782 +patch
Thanks

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.

https://github.com/graemeg/freepascal/commit/e8335a145bfe3af52eed8d0d74ae3a461bbe9d1e

I turned the commit into a quilt patch, added it to the quilt series, built the 
compiler and was able to confirm it fixed the issue.

Debdiff is attatched, if noone else gets round to it first I'll probably commit 
and upload within the next week or so.

diff -Nru fpc-3.0.4+dfsg/debian/changelog fpc-3.0.4+dfsg/debian/changelog
--- fpc-3.0.4+dfsg/debian/changelog     2019-01-16 09:14:10.000000000 +0000
+++ fpc-3.0.4+dfsg/debian/changelog     2019-01-24 23:27:02.000000000 +0000
@@ -1,3 +1,10 @@
+fpc (3.0.4+dfsg-22) UNRELEASED; urgency=medium
+
+  * debian/patches/arm64-select.patch
+    - Fix fpSelect with nil timestamp on aarch64 (closes: 888782)
+
+ -- Peter Michael Green <plugw...@debian.org>  Thu, 24 Jan 2019 23:27:02 +0000
+
 fpc (3.0.4+dfsg-21) unstable; urgency=medium
 
   [ Paul Gevers ]
diff -Nru fpc-3.0.4+dfsg/debian/patches/arm64-select.patch 
fpc-3.0.4+dfsg/debian/patches/arm64-select.patch
--- fpc-3.0.4+dfsg/debian/patches/arm64-select.patch    1970-01-01 
00:00:00.000000000 +0000
+++ fpc-3.0.4+dfsg/debian/patches/arm64-select.patch    2019-01-24 
23:26:42.000000000 +0000
@@ -0,0 +1,37 @@
+This patch is based on the commit detailed below with paths adjusted
+to match the Debian fpc package --plugwash
+commit e8335a145bfe3af52eed8d0d74ae3a461bbe9d1e
+Author: Marco van de Voort <mar...@stack.nl>
+Date:   Wed Mar 30 19:21:05 2016 +0000
+
+     * fix timespec=nil for -dgeneric_linux_syscalls (aarch64) case.
+    
+    
+    git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@33392 
3ad0048d-3df7-0310-abae-a5850022a9f2
+
+diff --git a/rtl/linux/bunxsysc.inc b/rtl/linux/bunxsysc.inc
+index c8d7849672..c6d18be4e9 100644
+--- a/fpcsrc/rtl/linux/bunxsysc.inc
++++ b/fpcsrc/rtl/linux/bunxsysc.inc
+@@ -463,12 +463,18 @@ Function 
fpSelect(N:cint;readfds,writefds,exceptfds:pfdSet;TimeOut:PTimeVal):cin
+ {$if defined(generic_linux_syscalls)}
+ 
+ var ts : timespec;
++    pts : PTimeSpec;
+ begin
+-  ts.tv_sec := timeout^.tv_sec;
+-  ts.tv_nsec := timeout^.tv_usec * 1000;
++  pts:=nil;
++  if assigned(timeout) then
++    begin
++      pts:=@ts;
++      ts.tv_sec := timeout^.tv_sec;
++      ts.tv_nsec := timeout^.tv_usec * 1000;
++    end;
+   fpSelect:=do_syscall(syscall_nr_pselect6,n,
+                        tsysparam(readfds),tsysparam(writefds),
+-                       tsysparam(exceptfds),tsysparam(@ts),0);
++                       tsysparam(exceptfds),tsysparam(pts),0);
+ end;
+ 
+ {$else}
diff -Nru fpc-3.0.4+dfsg/debian/patches/series 
fpc-3.0.4+dfsg/debian/patches/series
--- fpc-3.0.4+dfsg/debian/patches/series        2019-01-16 08:33:37.000000000 
+0000
+++ fpc-3.0.4+dfsg/debian/patches/series        2019-01-24 23:26:55.000000000 
+0000
@@ -34,3 +34,4 @@
 fpcmake-m68k.patch
 ncurses6.patch
 fpc-r38400.patch
+arm64-select.patch

Reply via email to