From c527e763377e6957054c483ecf4c714ad8c80299 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 30 Mar 2024 08:48:09 +0100 Subject: [PATCH] parse invalid jingle actions --- .../xmpp/jingle/JingleConnectionManager.java | 20 +++++++++++-------- .../xmpp/jingle/stanzas/JinglePacket.java | 11 ++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java index b70463eb0..c94ed0ab1 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnectionManager.java @@ -76,15 +76,20 @@ public class JingleConnectionManager extends AbstractConnectionManager { public void deliverPacket(final Account account, final JinglePacket packet) { final String sessionId = packet.getSessionId(); + final JinglePacket.Action action = packet.getAction(); if (sessionId == null) { respondWithJingleError(account, packet, "unknown-session", "item-not-found", "cancel"); return; } + if (action == null) { + respondWithJingleError(account, packet, null, "bad-request", "cancel"); + return; + } final AbstractJingleConnection.Id id = AbstractJingleConnection.Id.of(account, packet); final AbstractJingleConnection existingJingleConnection = connections.get(id); if (existingJingleConnection != null) { existingJingleConnection.deliverPacket(packet); - } else if (packet.getAction() == JinglePacket.Action.SESSION_INITIATE) { + } else if (action == JinglePacket.Action.SESSION_INITIATE) { final Jid from = packet.getFrom(); final Content content = packet.getJingleContent(); final String descriptionNamespace = @@ -153,7 +158,8 @@ public class JingleConnectionManager extends AbstractConnectionManager { rtpConnection.integrationFailure(); } - private void sendSessionTerminate(final Account account, final IqPacket request, final AbstractJingleConnection.Id id) { + private void sendSessionTerminate( + final Account account, final IqPacket request, final AbstractJingleConnection.Id id) { mXmppConnectionService.sendIqPacket( account, request.generateResponse(IqPacket.TYPE.RESULT), null); final JinglePacket sessionTermination = @@ -255,9 +261,9 @@ public class JingleConnectionManager extends AbstractConnectionManager { void respondWithJingleError( final Account account, final IqPacket original, - String jingleCondition, - String condition, - String conditionType) { + final String jingleCondition, + final String condition, + final String conditionType) { final IqPacket response = original.generateResponse(IqPacket.TYPE.ERROR); final Element error = response.addChild("error"); error.setAttribute("type", conditionType); @@ -1171,8 +1177,6 @@ public class JingleConnectionManager extends AbstractConnectionManager { public void onCallIntegrationAnswer() {} @Override - public void onCallIntegrationSilence() { - - } + public void onCallIntegrationSilence() {} } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java index 82c5b155c..a24040d3d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/JinglePacket.java @@ -142,8 +142,15 @@ public class JinglePacket extends IqPacket { TRANSPORT_REPLACE; public static Action of(final String value) { - // TODO handle invalid - return Action.valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, value)); + if (Strings.isNullOrEmpty(value)) { + return null; + } + try { + return Action.valueOf( + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, value)); + } catch (final IllegalArgumentException e) { + return null; + } } @Override