From fa3ef07580a0b8d40e1e2725d26647588c292f45 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 17 Apr 2020 10:29:36 +0200 Subject: [PATCH] be more strict with ice candidate parsing --- .../xmpp/jingle/JingleRtpConnection.java | 10 ++++++++-- .../xmpp/jingle/stanzas/IceUdpTransportInfo.java | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 8ad07028d..41445c77c 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -234,7 +234,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web for (final Map.Entry content : contentMap.contents.entrySet()) { final String ufrag = content.getValue().transport.getAttribute("ufrag"); for (final IceUdpTransportInfo.Candidate candidate : content.getValue().transport.getCandidates()) { - final String sdp = candidate.toSdpAttribute(ufrag); + final String sdp; + try { + sdp = candidate.toSdpAttribute(ufrag); + } catch (IllegalArgumentException e) { + Log.d(Config.LOGTAG,id.account.getJid().asBareJid()+": ignoring invalid ICE candidate "+e.getMessage()); + continue; + } final String sdpMid = content.getKey(); final int mLineIndex = identificationTags.indexOf(sdpMid); final IceCandidate iceCandidate = new IceCandidate(sdpMid, mLineIndex, sdp); @@ -418,8 +424,8 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web private void addIceCandidatesFromBlackLog() { while (!this.pendingIceCandidates.isEmpty()) { final IceCandidate iceCandidate = this.pendingIceCandidates.poll(); - this.webRTCWrapper.addIceCandidate(iceCandidate); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": added ICE candidate from back log " + iceCandidate); + this.webRTCWrapper.addIceCandidate(iceCandidate); } } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java index 467a25490..1e7ada424 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/stanzas/IceUdpTransportInfo.java @@ -5,6 +5,7 @@ import android.util.Log; import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; +import com.google.common.base.Strings; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; @@ -188,11 +189,17 @@ public class IceUdpTransportInfo extends GenericTransportInfo { public String toSdpAttribute(final String ufrag) { final String foundation = this.getAttribute("foundation"); + checkNotNullNoWhitespace(foundation, "foundation"); final String component = this.getAttribute("component"); + checkNotNullNoWhitespace(component, "component"); final String transport = this.getAttribute("protocol"); + checkNotNullNoWhitespace(transport, "protocol"); final String priority = this.getAttribute("priority"); + checkNotNullNoWhitespace(priority, "priority"); final String connectionAddress = this.getAttribute("ip"); + checkNotNullNoWhitespace(connectionAddress, "ip"); final String port = this.getAttribute("port"); + checkNotNullNoWhitespace(port, "port"); final Map additionalParameter = new LinkedHashMap<>(); final String relAddr = this.getAttribute("rel-addr"); final String type = this.getAttribute("type"); @@ -228,6 +235,13 @@ public class IceUdpTransportInfo extends GenericTransportInfo { } } + private static void checkNotNullNoWhitespace(final String value, final String name) { + if (Strings.isNullOrEmpty(value)) { + throw new IllegalArgumentException(String.format("Parameter %s is missing or empty", name)); + } + SessionDescription.checkNoWhitespace(value, String.format("Parameter %s contains white spaces", name)); + } + public static class Fingerprint extends Element {