[GH-ISSUE #13] Potential buffer over-read #12

Closed
opened 2026-05-05 03:29:44 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @jonirons on GitHub (Dec 3, 2021).
Original GitHub issue: https://github.com/cy384/ssheven/issues/13

I believe the following lines allow for a buffer over-read (however remote the possibility):

d8753b3676/ssheven.c (L35)
d8753b3676/ssheven.c (L39)

The arrays are length 255 rather than 256; in both cases, I think it's possible for the array to end up being indexed with [255], which over-reads the buffer.

When reading from ascii_to_control_code, you might send garbage across the wire:
d8753b3676/ssheven.c (L576)

For keycode_to_ascii, the index to the above read might also end up being garbage:
d8753b3676/ssheven.c (L571)

If this looks like a problem, you'll also want to update this loop:

d8753b3676/ssheven.c (L50)

to:

	for (uint16_t i = 0; i < 256; i++)

I don't know that any Mac keyboard would even have a key code on it equal to 0xff, nor do I know if the translation to "ASCII" would ever give 0xff. This latter seems like it could be possible if there is a layout with a ˇ key.

Originally created by @jonirons on GitHub (Dec 3, 2021). Original GitHub issue: https://github.com/cy384/ssheven/issues/13 I believe the following lines allow for a buffer over-read (however remote the possibility): https://github.com/cy384/ssheven/blob/d8753b3676a63b8763a5480817eaad5ce28e4735/ssheven.c#L35 https://github.com/cy384/ssheven/blob/d8753b3676a63b8763a5480817eaad5ce28e4735/ssheven.c#L39 The arrays are length `255` rather than `256`; in both cases, I think it's possible for the array to end up being indexed with `[255]`, which over-reads the buffer. When reading from `ascii_to_control_code`, you might send garbage across the wire: https://github.com/cy384/ssheven/blob/d8753b3676a63b8763a5480817eaad5ce28e4735/ssheven.c#L576 For `keycode_to_ascii`, the index to the above read might also end up being garbage: https://github.com/cy384/ssheven/blob/d8753b3676a63b8763a5480817eaad5ce28e4735/ssheven.c#L571 If this looks like a problem, you'll also want to update this loop: https://github.com/cy384/ssheven/blob/d8753b3676a63b8763a5480817eaad5ce28e4735/ssheven.c#L50 to: ``` for (uint16_t i = 0; i < 256; i++) ``` I don't know that any Mac keyboard would even have a key code on it equal to `0xff`, nor do I know if the translation to "ASCII" would ever give `0xff`. This latter seems like it could be possible if there is a layout with a `ˇ` key.
Author
Owner

@cy384 commented on GitHub (Dec 3, 2021):

thanks for the report, and for reading the code closely! should be an easy fix, I'll get to it this evening

<!-- gh-comment-id:985706341 --> @cy384 commented on GitHub (Dec 3, 2021): thanks for the report, and for reading the code closely! should be an easy fix, I'll get to it this evening
Author
Owner

@cy384 commented on GitHub (Dec 5, 2021):

should be fixed, thanks again

<!-- gh-comment-id:986156514 --> @cy384 commented on GitHub (Dec 5, 2021): should be fixed, thanks again
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/ssheven#12
No description provided.