Browse code

core: resolve - safety check for setting port

Daniel-Constantin Mierla authored on 15/04/2021 06:32:38
Showing 1 changed files
... ...
@@ -1225,7 +1225,7 @@ change:
1225 1225
  *   and *proto!=0 or port==0 && proto==0)
1226 1226
  * when performing SRV lookup (*port==0) it will use *proto to look for
1227 1227
  * tcp or udp hosts, otherwise proto is unused; if proto==0 => no SRV lookup
1228
- * If zt is set, name will be assumed to be 0 terminated and some copy 
1228
+ * If zt is set, name will be assumed to be 0 terminated and some copy
1229 1229
  * operations will be avoided.
1230 1230
  * If is_srv is set it will assume name has the srv prefixes for sip already
1231 1231
  *  appended and it's already 0-term'ed; if not it will append them internally.
... ...
@@ -1313,7 +1313,7 @@ struct hostent* srv_sip_resolvehost(str* name, int zt, unsigned short* port,
1313 1313
 do_srv:
1314 1314
 			/* try to find the SRV records inside previous ARs  first*/
1315 1315
 			for (l=ars; l; l=l->next){
1316
-				if (l->type!=T_SRV) continue; 
1316
+				if (l->type!=T_SRV) continue;
1317 1317
 				srv=(struct srv_rdata*) l->rdata;
1318 1318
 				if (srv==0){
1319 1319
 					LM_CRIT("null rdata\n");
... ...
@@ -1325,7 +1325,7 @@ do_srv:
1325 1325
 					/* we found it*/
1326 1326
 					LM_DBG("found SRV(%s) = %s:%d in AR\n",
1327 1327
 							srv_target, srv->name, srv->port);
1328
-					*port=srv->port;
1328
+					if(port) *port=srv->port;
1329 1329
 					/* cleanup on exit */
1330 1330
 					goto end;
1331 1331
 				}
... ...
@@ -1344,7 +1344,7 @@ do_srv:
1344 1344
 					/* we found it*/
1345 1345
 					LM_DBG("SRV(%s) = %s:%d\n",
1346 1346
 							srv_target, srv->name, srv->port);
1347
-					*port=srv->port;
1347
+					if(port) *port=srv->port;
1348 1348
 					/* cleanup on exit */
1349 1349
 					goto end;
1350 1350
 				}
... ...
@@ -1356,7 +1356,7 @@ do_srv:
1356 1356
 				goto end;
1357 1357
 			}
1358 1358
 			/* cleanup on exit */
1359
-			LM_DBG("no SRV record found for %.*s," 
1359
+			LM_DBG("no SRV record found for %.*s,"
1360 1360
 					" trying 'normal' lookup...\n", name->len, name->s);
1361 1361
 		}
1362 1362
 	}