diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 3f45550543f32aeb223c04ed0bc850d21ff8979e..bb67890a033a68babd9a4aa74b92f28cb7c2497f 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -15295,6 +15295,10 @@ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct soc
 		if (sscanf(e, "%d %n", &respid, &len) != 1) {
 			ast_log(LOG_WARNING, "Invalid response: '%s'\n", e);
 		} else {
+			if (respid <= 0) {
+				ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid);
+				return 0;
+			}
 			/* More SIP ridiculousness, we have to ignore bogus contacts in 100 etc responses */
 			if ((respid == 200) || ((respid >= 300) && (respid <= 399)))
 				extract_uri(p, req);