Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow in tbh handling routines when char != unsigned char #1

Closed
fayoh opened this issue Nov 10, 2010 · 3 comments
Closed

Overflow in tbh handling routines when char != unsigned char #1

fayoh opened this issue Nov 10, 2010 · 3 comments

Comments

@fayoh
Copy link

fayoh commented Nov 10, 2010

It seems that the tbh handling functions (get_tbh_size and set_tbh_size) are suffering from an arithmetic overflow when all 8 lower bits are used, making the connection close when dealing with messages between 128 and 255 bytes.

Simplistic patch that at least makes the issues go away in my environment.

diff --git a/c_src/serial.c b/c_src/serial.c
index 8751be6..895e0aa 100644
--- a/c_src/serial.c
+++ b/c_src/serial.c
@@ -214,7 +214,7 @@ void set_tty_speed(int fd, speed_t new_ispeed, speed_t     new_ospeed)
  * Desc: returns the size of a two_byte_header message (from Erlang).
  */

-int get_tbh_size(char buf[])
+int get_tbh_size(unsigned char buf[])
 {
   return (((int) buf[0]) << 8) + ((int) buf[1]);
 }
@@ -441,7 +441,7 @@ main(int argc, char *argv[])
   {
     fd_set readfds;           /* file descriptor bit field for select */
     int    maxfd;             /* max file descriptor for select */
-    char   buf[MAXLENGTH];    /* buffer for transfer between serial-user */
+    unsigned char buf[MAXLENGTH];/* buffer for transfer between serial-user */
     int    escapes;           /* number of consecutive escapes in cbreak */

     /* Set up initial bit field for select */
@tonyg
Copy link
Owner

tonyg commented Feb 7, 2011

Switch to unsigned-char buffer. Closed by 6e0138f.

@tonyg
Copy link
Owner

tonyg commented Feb 7, 2011

Hi fayoh, I hope this fixes the issue for you.

@tonyg
Copy link
Owner

tonyg commented Feb 7, 2011

And thank you very much for pointing out the problem and the patch!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants