chiark
/
gitweb
/
~ian
/
secnet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
integer arithmetic types: correct perhaps-possible negative timeout situation
[secnet.git]
/
ipaddr.c
diff --git
a/ipaddr.c
b/ipaddr.c
index d8661dafcd4535560d3b83988096ad293ac4a763..8de384bfa190afadc7da9731a77c1ca9d794eac0 100644
(file)
--- a/
ipaddr.c
+++ b/
ipaddr.c
@@
-2,6
+2,8
@@
inspired by the 'ipaddr.py' library from Cendio Systems AB. */
#include "secnet.h"
inspired by the 'ipaddr.py' library from Cendio Systems AB. */
#include "secnet.h"
+#include <limits.h>
+#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "ipaddr.h"
#include <stdio.h>
#include <string.h>
#include "ipaddr.h"
@@
-15,7
+17,7
@@
struct subnet_list *subnet_list_new(void)
r=safe_malloc(sizeof(*r),"subnet_list_new:list");
r->entries=0;
r->alloc=DEFAULT_ALLOC;
r=safe_malloc(sizeof(*r),"subnet_list_new:list");
r->entries=0;
r->alloc=DEFAULT_ALLOC;
- r->list=safe_malloc
(sizeof(*r->list)*
r->alloc,"subnet_list_new:data");
+ r->list=safe_malloc
_ary(sizeof(*r->list),
r->alloc,"subnet_list_new:data");
return r;
}
return r;
}
@@
-31,6
+33,7
@@
static void subnet_list_set_len(struct subnet_list *a, uint32_t l)
uint32_t na;
if (l>a->alloc) {
uint32_t na;
if (l>a->alloc) {
+ assert(a->alloc < (int)(INT_MAX/sizeof(*nd))-EXTEND_ALLOC_BY);
na=a->alloc+EXTEND_ALLOC_BY;
nd=realloc(a->list,sizeof(*nd)*na);
if (!nd) {
na=a->alloc+EXTEND_ALLOC_BY;
nd=realloc(a->list,sizeof(*nd)*na);
if (!nd) {
@@
-45,6
+48,7
@@
static void subnet_list_set_len(struct subnet_list *a, uint32_t l)
void subnet_list_append(struct subnet_list *a, uint32_t prefix, uint32_t len)
{
struct subnet *sn;
void subnet_list_append(struct subnet_list *a, uint32_t prefix, uint32_t len)
{
struct subnet *sn;
+ assert(a->entries < INT_MAX);
subnet_list_set_len(a,a->entries+1);
sn=&a->list[a->entries-1];
sn->prefix=prefix;
subnet_list_set_len(a,a->entries+1);
sn=&a->list[a->entries-1];
sn->prefix=prefix;
@@
-114,6
+118,7
@@
static void ipset_set_len(struct ipset *a, uint32_t l)
uint32_t na;
if (l>a->a) {
uint32_t na;
if (l>a->a) {
+ assert(a->a < INT_MAX-EXTEND_ALLOC_BY);
na=a->a+EXTEND_ALLOC_BY;
nd=realloc(a->d,sizeof(*nd)*na);
if (!nd) {
na=a->a+EXTEND_ALLOC_BY;
nd=realloc(a->d,sizeof(*nd)*na);
if (!nd) {