Mapepire-IBMi / mapepire-server

Server-side support for Code for IBM i
GNU General Public License v3.0
24 stars 8 forks source link

Fixing crash on bad request due to NullPointerException #73

Open bashdi opened 1 month ago

bashdi commented 1 month ago

Sending a request where the type needs additional json-properties leads to a NullPointerException which crashes the application.

Example: {"id":"1","type":"execute"}

java.lang.RuntimeException: Bad request: Correlation ID not specified at com.github.ibm.mapepire.requests.BadReq.go(BadReq.java:22) at com.github.ibm.mapepire.ClientRequest.run(ClientRequest.java:85) at java.base/java.lang.Thread.run(Thread.java:840) java.sql.SQLException: Not connected at com.github.ibm.mapepire.SystemConnection.getJdbcConnection(SystemConnection.java:141) at com.github.ibm.mapepire.DataStreamProcessor.end(DataStreamProcessor.java:209) at com.github.ibm.mapepire.ws.DbWebsocketClient.onWebSocketError(DbWebsocketClient.java:50) at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onError(JettyListenerEventDriver.java:169) at org.eclipse.jetty.websocket.common.WebSocketSession.callApplicationOnError(WebSocketSession.java:416) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.close(AbstractWebSocketConnection.java:209) at org.eclipse.jetty.websocket.common.WebSocketSession.close(WebSocketSession.java:130) at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:173) at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:326) at org.eclipse.jetty.websocket.common.extensions.AbstractExtension.nextIncomingFrame(AbstractExtension.java:148) at org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension.nextIncomingFrame(PerMessageDeflateExtension.java:111) at org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension.incomingFrame(PerMessageDeflateExtension.java:71) at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:202) at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:225) at org.eclipse.jetty.websocket.common.Parser.parseSingleFrame(Parser.java:259) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:459) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:440) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:137) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) at java.base/java.lang.Thread.run(Thread.java:840) java.sql.SQLException: Not connected at com.github.ibm.mapepire.SystemConnection.getJdbcConnection(SystemConnection.java:141) at com.github.ibm.mapepire.DataStreamProcessor.end(DataStreamProcessor.java:209) at com.github.ibm.mapepire.ws.DbWebsocketClient.onWebSocketClose(DbWebsocketClient.java:43) at org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onClose(JettyListenerEventDriver.java:149) at org.eclipse.jetty.websocket.common.WebSocketSession.callApplicationOnClose(WebSocketSession.java:394) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.close(AbstractWebSocketConnection.java:225) at org.eclipse.jetty.websocket.common.WebSocketSession.close(WebSocketSession.java:130) at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:173) at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:326) at org.eclipse.jetty.websocket.common.extensions.AbstractExtension.nextIncomingFrame(AbstractExtension.java:148) at org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension.nextIncomingFrame(PerMessageDeflateExtension.java:111) at org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension.incomingFrame(PerMessageDeflateExtension.java:71) at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:202) at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:225) at org.eclipse.jetty.websocket.common.Parser.parseSingleFrame(Parser.java:259) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:459) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:440) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:137) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) at java.base/java.lang.Thread.run(Thread.java:840) java.lang.NullPointerException: Cannot invoke "com.github.ibm.mapepire.DataStreamProcessor.sendResponse(String)" because "this.m_io" is null at com.github.ibm.mapepire.ClientRequest.sendreply(ClientRequest.java:129) at com.github.ibm.mapepire.ClientRequest.run(ClientRequest.java:98) at java.base/java.lang.Thread.run(Thread.java:840)

I fixed it with passing the current instance instead of null to the BadReq-constructor like it was done with all the other ClientRequest-Types.

jonnyz32 commented 1 month ago

@bashdi Can you create a pr on the mapepire client with a test that will verify this fix?

ThePrez commented 1 month ago

I had to make a small change but the fix seems to be working and is safe to merge IMO

@bashdi , I am curious however, how you encountered this issue? Were you testing the server directly, or was this exposed through one of the clients?

bashdi commented 1 month ago

@ThePrez I issued the task of building a mapepire client to a trainee. He triggered this crash with a direct webscoket connection and/or postman.