Check-in [52fcd859c7]
Overview
SHA1:52fcd859c7f8e51580f2fa751830db32382aafc6
Date: 2009-05-24 21:00:59
User: rmiller
Comment:A little defensive programming...
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2009-06-01
03:32
[576df9e8bd] Test commit, ignore. (user: rkeene, tags: trunk)
2009-05-24
21:00
[52fcd859c7] A little defensive programming... (user: rmiller, tags: trunk)
18:29
[d4b45fb52e] Change to uint8_t per Julien. (user: rmiller, tags: trunk)
Changes

Modified packetbl.c from [b3fcc2e443] to [cd3b07c2c0].

  1367   1367    *   without aborting.
  1368   1368    *
  1369   1369    */
  1370   1370   int check_packet_list(const struct packet_info *ip, struct config_entry *list) {
  1371   1371   
  1372   1372   	struct config_entry *wltmp = NULL;
  1373   1373   	unsigned int ip_proc;
         1374  +	int rv;
  1374   1375   
  1375   1376   	if (ip == NULL || list == NULL) {
  1376   1377   		return 0;
  1377   1378   	}
  1378   1379   
  1379   1380   	ip_proc = ip->b1 << 24;
  1380   1381   	ip_proc |= ip->b2 << 16;
................................................................................
  1386   1387   	while (1) {
  1387   1388   		uint32_t p = 0;
  1388   1389   
  1389   1390   		p = ip_proc;
  1390   1391   		p &= wltmp->cidr.processed;
  1391   1392   
  1392   1393   		if (p == wltmp->cidr.ip) {
  1393         -			snprintf(msgbuf, sizeof(msgbuf), "%hhu.%hhu.%hhu.%hhu %x/%d",
  1394         -				ip->b1, ip->b2, ip->b3, ip->b4,
  1395         -				wltmp->cidr.ip, wltmp->cidr.network);
         1394  +			rv = snprintf(msgbuf, sizeof(msgbuf), 
         1395  +					"%hhu.%hhu.%hhu.%hhu %x/%d",
         1396  +					ip->b1, ip->b2, ip->b3, ip->b4,
         1397  +					wltmp->cidr.ip, wltmp->cidr.network);
         1398  +			if (rv < 0) {
         1399  +				syslog(LOG_ERR, "snprintf failed at line %d: %s",
         1400  +					__LINE__, strerror(errno));
         1401  +				exit (1);
         1402  +			}
  1396   1403   			return 1;
  1397   1404   		}
  1398   1405   
  1399   1406   		if (wltmp->next == NULL) {
  1400   1407   			break;
  1401   1408   		}
  1402   1409   
................................................................................
  1422   1429    *   This function takes the data in the parameter "ip" and stores an ASCII
  1423   1430    *   representation in the global variable "msgbuf."
  1424   1431    *   It must be able to cope with "ip" being NULL.
  1425   1432    *
  1426   1433    */
  1427   1434   static void get_ip_string(const struct packet_info *ip) {
  1428   1435   
         1436  +	int rv;
         1437  +	
  1429   1438   	if (ip == NULL) {
  1430         -		sprintf(msgbuf, "-");
         1439  +		rv = sprintf(msgbuf, "-");
         1440  +		if (rv < 0) {	
         1441  +			syslog(LOG_ERR, "sprintf failed in line %d: %s",
         1442  +				__LINE__, strerror(errno));
         1443  +			exit(1);
         1444  +		}
  1431   1445   		return;
  1432   1446   	}
  1433   1447   
  1434         -	snprintf(msgbuf, sizeof(msgbuf), "%hhu.%hhu.%hhu.%hhu:%d.%d", ip->b1, 
  1435         -		ip->b2, ip->b3, ip->b4,
  1436         -		ip->s_port,ip->d_port);
         1448  +	rv = snprintf(msgbuf, sizeof(msgbuf), "%hhu.%hhu.%hhu.%hhu:%d.%d", 
         1449  +			ip->b1, ip->b2, ip->b3, ip->b4,
         1450  +			ip->s_port,ip->d_port);
         1451  +		if (rv < 0) {
         1452  +			syslog(LOG_ERR, "snprintf failed in line %d: %s",
         1453  +				__LINE__, strerror(errno));
         1454  +			exit(1);
         1455  +		}
  1437   1456   	return;
  1438   1457   }
  1439   1458   
  1440   1459   #ifdef USE_SOCKSTAT
  1441   1460   /*
  1442   1461    * SYNOPSIS:
  1443   1462    *   void *pbl_sockstat_thread(