I found a bug where my Java application (JVM) completely crashes. The problem is within the call to "SerialPort::readBytes()" In order to know how many bytes need to be read a call to "getInputBufferBytesCount()" is done leading to a native method call: "serialInterface.getBuffersBytesCount(portHandle)[0]". The c++ implementation found in "src/main/cpp/_nix_based/jssc.cpp" then calls "ioctl(portHandle, FIONREAD, &returnValues[0])" and "ioctl(portHandle, TIOCOUTQ, &returnValues[1])" without checking the return value of ioctl, which in my case can be an error. By ignoring the error, values like 222914544 get written into returnValues[0] / returnValues[1]. These values are than used in the native method "Java_jssc_SerialNativeInterface_readBytes" to create an array for the bytes to read, leading to memory problems and therefor crashing the JVM completely.
I am running the application on a linux based system with two devices connected via USB. One device is controlled via the serial interface and I found out that the problem occurrs if the other one does some kind of file copy operation meanwhile (a normal USB stick file copy).
By checking the return value I saw that the big numbers occur if the return value of ioctl is less than 0 (error case). The "std::strerror(errno)" returns "Invalid argument" in my situation there. This should lead to an exception that is handled a) by jssc or b) thrown up to java to handle it there. But ignoring it leads to serious problems that can not be handled by a jssc using application.
@Xerxekyran I believe this is fixed via #138. Please request a reopen if this is incorrect. Furthemore, Please let me know if you need a one-off build for testing.
Hi there, first of all thanks for the great work.
I found a bug where my Java application (JVM) completely crashes. The problem is within the call to "SerialPort::readBytes()" In order to know how many bytes need to be read a call to "getInputBufferBytesCount()" is done leading to a native method call: "serialInterface.getBuffersBytesCount(portHandle)[0]". The c++ implementation found in "src/main/cpp/_nix_based/jssc.cpp" then calls "ioctl(portHandle, FIONREAD, &returnValues[0])" and "ioctl(portHandle, TIOCOUTQ, &returnValues[1])" without checking the return value of ioctl, which in my case can be an error. By ignoring the error, values like 222914544 get written into returnValues[0] / returnValues[1]. These values are than used in the native method "Java_jssc_SerialNativeInterface_readBytes" to create an array for the bytes to read, leading to memory problems and therefor crashing the JVM completely.
I am running the application on a linux based system with two devices connected via USB. One device is controlled via the serial interface and I found out that the problem occurrs if the other one does some kind of file copy operation meanwhile (a normal USB stick file copy).
By checking the return value I saw that the big numbers occur if the return value of ioctl is less than 0 (error case). The "std::strerror(errno)" returns "Invalid argument" in my situation there. This should lead to an exception that is handled a) by jssc or b) thrown up to java to handle it there. But ignoring it leads to serious problems that can not be handled by a jssc using application.