Browse code

geoip: for safety checks for the case when geoip_match() is not executed

- but the geoip pv is accessed
- reported by Juha Heinanen

(cherry picked from commit 56ed48bf48c3d78ff5d214833e09a5759f0b5928)

Daniel-Constantin Mierla authored on 04/03/2014 08:43:39
Showing 1 changed files
... ...
@@ -257,6 +257,8 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
257 257
 			{
258 258
 				if(gpv->item->r.flags&1)
259 259
 					return pv_get_null(msg, param, res);
260
+				if(gpv->item->r.record==NULL)
261
+					return pv_get_null(msg, param, res);
260 262
 				gpv->item->r.time_zone
261 263
 					= (char*)GeoIP_time_zone_by_country_and_region(
262 264
 						gpv->item->r.record->country_code,
... ...
@@ -266,11 +268,15 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
266 268
 			return pv_geoip_get_strzval(msg, param, res,
267 269
 					gpv->item->r.time_zone);
268 270
 		case 2: /* zip */
271
+			if(gpv->item->r.record==NULL)
272
+				return pv_get_null(msg, param, res);
269 273
 			return pv_geoip_get_strzval(msg, param, res,
270 274
 					gpv->item->r.record->postal_code);
271 275
 		case 3: /* lat */
272 276
 			if((gpv->item->r.flags&2)==0)
273 277
 			{
278
+				if(gpv->item->r.record==NULL)
279
+					return pv_get_null(msg, param, res);
274 280
 				snprintf(gpv->item->r.latitude, 15, "%f",
275 281
 						gpv->item->r.record->latitude);
276 282
 				gpv->item->r.flags |= 2;
... ...
@@ -280,6 +286,8 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
280 286
 		case 4: /* lon */
281 287
 			if((gpv->item->r.flags&4)==0)
282 288
 			{
289
+				if(gpv->item->r.record==NULL)
290
+					return pv_get_null(msg, param, res);
283 291
 				snprintf(gpv->item->r.longitude, 15, "%f",
284 292
 						gpv->item->r.record->longitude);
285 293
 				gpv->item->r.flags |= 4;
... ...
@@ -287,6 +295,8 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
287 295
 			return pv_geoip_get_strzval(msg, param, res,
288 296
 					gpv->item->r.longitude);
289 297
 		case 5: /* dma */
298
+			if(gpv->item->r.record==NULL)
299
+				return pv_get_null(msg, param, res);
290 300
 			return pv_get_sintval(msg, param, res,
291 301
 					gpv->item->r.record->dma_code);
292 302
 		case 6: /* ips */
... ...
@@ -308,14 +318,20 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
308 318
 			return pv_geoip_get_strzval(msg, param, res,
309 319
 					gpv->item->r.record->city);
310 320
 		case 9: /* area */
321
+			if(gpv->item->r.record==NULL)
322
+				return pv_get_null(msg, param, res);
311 323
 			return pv_get_sintval(msg, param, res,
312 324
 					gpv->item->r.record->area_code);
313 325
 		case 10: /* regc */
326
+			if(gpv->item->r.record==NULL)
327
+				return pv_get_null(msg, param, res);
314 328
 			return pv_geoip_get_strzval(msg, param, res,
315 329
 					gpv->item->r.record->region);
316 330
 		case 11: /* regn */
317 331
 			if((gpv->item->r.flags&16)==0)
318 332
 			{
333
+				if(gpv->item->r.record==NULL)
334
+					return pv_get_null(msg, param, res);
319 335
 				gpv->item->r.region_name
320 336
 						= (char*)GeoIP_region_name_by_code(
321 337
 							gpv->item->r.record->country_code,
... ...
@@ -325,9 +341,13 @@ int pv_get_geoip(struct sip_msg *msg, pv_param_t *param,
325 341
 			return pv_geoip_get_strzval(msg, param, res,
326 342
 					gpv->item->r.region_name);
327 343
 		case 12: /* metro */
344
+			if(gpv->item->r.record==NULL)
345
+				return pv_get_null(msg, param, res);
328 346
 			return pv_get_sintval(msg, param, res,
329 347
 					gpv->item->r.record->metro_code);
330 348
 		default: /* cc */
349
+			if(gpv->item->r.record==NULL)
350
+				return pv_get_null(msg, param, res);
331 351
 			return pv_geoip_get_strzval(msg, param, res,
332 352
 					gpv->item->r.record->country_code);
333 353
 	}