Open bug on binding to network address fails

2014-07-17
2014-07-17
  • Andrew Stanton

    Andrew Stanton - 2014-07-17

    Hello,

    In 2.6.1, the code worked to specify a name/IP address with the port to bind to, such as:

    localhost,2000:telnet:0:/dev/ttyUSB0:9600 ...

    In 2.8+, this fails with:

    "ser2net: Error on line x, port number was invalid"

    Upon review I found that the scan_tcp_port is called multiple times in the code.

    strtok_r is used on the str argument that is passed which is the port->portname member of the structure.

    This modifies the str when a token is found, such as only when an address is present with the port in the configuration file.

    strtok_r is known to modify the input string

    http://linux.die.net/man/3/strtok_r
    "These functions modify their first argument."

    Thus, to make scan_tcp_port safe, we need to copy the original string. I suggest the following three lines:

    • char str_copy[NI_MAXHOST+NI_MAXSERV+1];
    • strcpy(str_copy, str);

    • ip = strtok_r(str_copy, ",", &strtok_data);

    • ip = strtok_r(str, ",", &strtok_data);

    I would like a bug opened for this issue.

    Regards
    ~ Andrew

     
    • Corey Minyard

      Corey Minyard - 2014-07-17

      I believe this is already fixed by git commit
      d34e66db65aa2e2c336ad40cb75a116d4cee4e42. Current ser2net is 2.10.0.

      -corey

      On 07/17/2014 10:02 AM, Andrew Stanton wrote:

      Hello,

      In 2.6.1, the code worked to specify a name/IP address with the port
      to bind to, such as:

      localhost,2000:telnet:0:/dev/ttyUSB0:9600 ...

      In 2.8+, this fails with:

      "ser2net: Error on line x, port number was invalid"

      Upon review I found that the scan_tcp_port is called multiple times in
      the code.

      strtok_r is used on the str argument that is passed which is the
      port->portname member of the structure.

      This modifies the str when a token is found, such as only when an
      address is present with the port in the configuration file.

      strtok_r is known to modify the input string

      http://linux.die.net/man/3/strtok_r
      "These functions modify their first argument."

      Thus, to make scan_tcp_port safe, we need to copy the original string.
      I suggest the following three lines:

      • char str_copy[NI_MAXHOST+NI_MAXSERV+1];
        *

        strcpy(str_copy, str);

      *

      ip = strtok_r(str_copy, ",", &strtok_data);
      
      • ip = strtok_r(str, ",", &strtok_data);

      I would like a bug opened for this issue.

      Regards
      ~ Andrew


      Open bug on binding to network address fails
      https://sourceforge.net/p/ser2net/discussion/90083/thread/b8220fa4/?limit=25#39b9


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/ser2net/discussion/90083/
      https://sourceforge.net/p/ser2net/discussion/90083

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/
      https://sourceforge.net/auth/subscriptions

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks