Browse code

core: resolve - safety check for setting port

(cherry picked from commit 703d6202e73e4e3778a2c66f4e29ae87dc6ac211)
(cherry picked from commit 1e6561f86d4a139834952ff21b74ecca0b508966)

Daniel-Constantin Mierla authored on 15/04/2021 06:32:38 • Henning Westerholt committed on 22/10/2021 11:52:42
Showing 1 changed files
... ...
@@ -1210,7 +1210,7 @@ change:
1210 1210
  *   and *proto!=0 or port==0 && proto==0)
1211 1211
  * when performing SRV lookup (*port==0) it will use *proto to look for
1212 1212
  * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup
1213
- * If zt is set, name will be assumed to be 0 terminated and some copy 
1213
+ * If zt is set, name will be assumed to be 0 terminated and some copy
1214 1214
  * operations will be avoided.
1215 1215
  * If is_srv is set it will assume name has the srv prefixes for sip already
1216 1216
  *  appended and it's already 0-term'ed; if not it will append them internally.
... ...
@@ -1298,7 +1298,7 @@ struct hostent* srv_sip_resolvehost(str* name, int zt, unsigned short* port,
1298 1298
 do_srv:
1299 1299
 			/* try to find the SRV records inside previous ARs  first*/
1300 1300
 			for (l=ars; l; l=l->next){
1301
-				if (l->type!=T_SRV) continue; 
1301
+				if (l->type!=T_SRV) continue;
1302 1302
 				srv=(struct srv_rdata*) l->rdata;
1303 1303
 				if (srv==0){
1304 1304
 					LM_CRIT("null rdata\n");
... ...
@@ -1310,7 +1310,7 @@ do_srv:
1310 1310
 					/* we found it*/
1311 1311
 					LM_DBG("found SRV(%s) = %s:%d in AR\n",
1312 1312
 							srv_target, srv->name, srv->port);
1313
-					*port=srv->port;
1313
+					if(port) *port=srv->port;
1314 1314
 					/* cleanup on exit */
1315 1315
 					goto end;
1316 1316
 				}
... ...
@@ -1329,7 +1329,7 @@ do_srv:
1329 1329
 					/* we found it*/
1330 1330
 					LM_DBG("SRV(%s) = %s:%d\n",
1331 1331
 							srv_target, srv->name, srv->port);
1332
-					*port=srv->port;
1332
+					if(port) *port=srv->port;
1333 1333
 					/* cleanup on exit */
1334 1334
 					goto end;
1335 1335
 				}
... ...
@@ -1341,7 +1341,7 @@ do_srv:
1341 1341
 				goto end;
1342 1342
 			}
1343 1343
 			/* cleanup on exit */
1344
-			LM_DBG("no SRV record found for %.*s," 
1344
+			LM_DBG("no SRV record found for %.*s,"
1345 1345
 					" trying 'normal' lookup...\n", name->len, name->s);
1346 1346
 		}
1347 1347
 	}