Skip to content

Commit af6139d

Browse files
Claudia PellegrinoClaudia Pellegrino
Claudia Pellegrino
authored and
Claudia Pellegrino
committed
Fix segfault if file descriptor unavailable
The `get_java_var_long` function returns 0 in several failure modes, e.g. if a file descriptor is unavailable. [1] However, one of the call sites is missing the result check, which causes a JVM segfault if the return value is 0. The segfault occurs on dereferencing the pointer: [2] ```c eis->eventflags[SPE_DATA_AVAILABLE] ``` Add a result value check, throwing a proper IOException if it is 0. See also similar issue NeuronRobotics#59. [3] Fixes NeuronRobotics#112 [4], NeuronRobotics#136 [5] and NeuronRobotics#242 [6]. [1]: https://github.com/NeuronRobotics/nrjavaserial/blob/0df8b60485a56d7698b71183237b5615d02a8194/src/main/c/src/SerialImp.c#L5137-L5142 [2]: https://github.com/NeuronRobotics/nrjavaserial/blob/0df8b60485a56d7698b71183237b5615d02a8194/src/main/c/src/SerialImp.c#L3085 [3]: NeuronRobotics#59 [4]: NeuronRobotics#112 [5]: NeuronRobotics#136 [6]: NeuronRobotics#242 Reported-by: Alex Vasiliev <@alex-vas> Reported-by: Łukasz Dywicki <[email protected]> Reported-by: Jose Pacelli <[email protected]> Reported-by: Frank Hartwig <[email protected]>
1 parent 0df8b60 commit af6139d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/c/src/SerialImp.c

+5
Original file line numberDiff line numberDiff line change
@@ -3081,6 +3081,11 @@ int read_byte_array( JNIEnv *env,
30813081
struct event_info_struct *eis = ( struct event_info_struct * )
30823082
get_java_var_long( env, *jobj,"eis","J" );
30833083

3084+
if (eis == NULL) {
3085+
throw_java_exception(env, IO_EXCEPTION, "read_byte_array",
3086+
"Unable to read byte array");
3087+
return -1;
3088+
}
30843089
report_time_start();
30853090
flag = eis->eventflags[SPE_DATA_AVAILABLE];
30863091
eis->eventflags[SPE_DATA_AVAILABLE] = 0;

0 commit comments

Comments
 (0)