[cffi-devel] Fwd: CFFI should defend itself against fragile handling of narrow return types in SBCL on x86!

Jean-Claude Beaudoin jean.claude.beaudoin at gmail.com
Sat Mar 28 17:53:00 UTC 2009


The mailer of common-lisp.net dropped to the floor the previous transmission
of the following message, so here it is again.

Cheers,

Jean-Claude Beaudoin


---------- Forwarded message ----------
From: Jean-Claude Beaudoin <jean.claude.beaudoin at gmail.com>
Date: Wed, Mar 25, 2009 at 1:13 AM
Subject: CFFI should defend itself against fragile handling of narrow return
types in SBCL on x86!
To: cffi-devel at common-lisp.net



Recent versions of GCC appear to be leaving spurious bits in the %eax
register used to return the value of a C function on x86 based platforms
when the return type is narrower than 32 bits (ie: short or char).  SBCL
does not defend itself against such register pollution and will return an
incorrect value made up of those spurious bits in addition to the intended
value.  A partial fix for "signed" short and char has appeared in SBCL
1.0.25 but the "unsigned" cases are still vulnerable.  I suggest that CFFI
should defend itself against that dangerously permissive handling of narrow
return types in SBCL through the use of a few filtering functions to be
applied in those relevant cases, at least until SBCL fixes the issue for
good.

Here is attached a patch against CFFI 0.10.4 with a version of the required
code.

I also attach a set of test files that can be used to illustrate the
problem.

Cheers,

Jean-Claude Beaudoin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20090328/b3a9bec6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cffi_0.10.4_sbcl_strict_widening.patch
Type: application/octet-stream
Size: 3229 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20090328/b3a9bec6/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: widening.tar.gz
Type: application/x-gzip
Size: 28853 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20090328/b3a9bec6/attachment.bin>


More information about the cffi-devel mailing list