Browse code

core: resolve - safety check for setting port

(cherry picked from commit 703d6202e73e4e3778a2c66f4e29ae87dc6ac211)

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