UB in derivation.c

Edoardo Sanguineti <[email protected]> Tue, 1 Nov 2022 21:26:58 +0000
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <CAKASqpEOezuM4F3pOnkP3c4Jv2gZ+751Ohj9EN1w1Z2MBdHd3w@mail.gmail.com>
--000000000000fcc57905ec6f62bd
Content-Type: text/plain; charset="UTF-8"

Hello,
I think I found undefined behaviour in the function all_spaces in the file
derivation.c
I believe there is a missing cast to unsigned char before the call to the
function c_isspace (see here:
https://git.savannah.gnu.org/cgit/bison.git/tree/src/derivation.c#n166).

I searched all usages of c_isspace in the source code of bison and this is
the only occurrence the cast to unsigned char is missing so I think that
should be fixed.

This is my first time sending a patch via email to a gnu project so I hope
this is the correct way to go about it.
I am unable to figure out how checkout the cvs repository locally, so I
git-cloned the official git repository and made a patch from there. I will
attach the patch to this email. I sincerely hope this is sufficient enough
for me to help.

Best,
Edoardo

--000000000000fcc57905ec6f62bd
Content-Type: application/octet-stream; 
	name="0001-derivation.c-fix-undefined-behaviour-in-all_spaces.patch"
Content-Disposition: attachment; 
	filename="0001-derivation.c-fix-undefined-behaviour-in-all_spaces.patch"
Content-Transfer-Encoding: base64
Content-ID: <f_l9ypzmdc0>
X-Attachment-Id: f_l9ypzmdc0

RnJvbSAzNWFmNWRjOWNmMjVkNjMxNDhlNDVmODAzNDJlNWJiZjk2NGZjZDA5IE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBGdXR1cmVSYXZlIDxlZG9hcmRvLnNhbmd1aW5ldGkyMjJAZ21h
aWwuY29tPgpEYXRlOiBUdWUsIDEgTm92IDIwMjIgMjA6NTA6MDUgKzAwMDAKU3ViamVjdDogW1BB
VENIXSBkZXJpdmF0aW9uLmM6IGZpeCB1bmRlZmluZWQgYmVoYXZpb3VyIGluIGFsbF9zcGFjZXMK
VG86IGJpc29uLXBhdGNoZXNAZ251Lm9yZwoKLS0tCiBzcmMvZGVyaXZhdGlvbi5jIHwgMiArLQog
MSBmaWxlIGNoYW5nZWQsIDEgaW5zZXJ0aW9uKCspLCAxIGRlbGV0aW9uKC0pCgpkaWZmIC0tZ2l0
IGEvc3JjL2Rlcml2YXRpb24uYyBiL3NyYy9kZXJpdmF0aW9uLmMKaW5kZXggZjk2ZWQ0YTcuLjkw
ZmZkNzg4IDEwMDY0NAotLS0gYS9zcmMvZGVyaXZhdGlvbi5jCisrKyBiL3NyYy9kZXJpdmF0aW9u
LmMKQEAgLTE2Myw3ICsxNjMsNyBAQCBkZXJpdmF0aW9uX2RlcHRoIChjb25zdCBkZXJpdmF0aW9u
ICpkZXJpdikKIHN0YXRpYyBib29sCiBhbGxfc3BhY2VzIChjb25zdCBjaGFyICpzKQogewotICB3
aGlsZSAoY19pc3NwYWNlICgqcykpCisgIHdoaWxlIChjX2lzc3BhY2UgKCh1bnNpZ25lZCBjaGFy
KSAqcykpCiAgICAgcysrOwogICByZXR1cm4gKnMgPT0gJ1wwJzsKIH0KLS0gCjIuMzcuMy53aW5k
b3dzLjEKCg==
--000000000000fcc57905ec6f62bd--