1
0
mirror of https://github.com/osmarks/ngircd.git synced 2025-07-06 11:52:50 +00:00

fix possibe buffer-off-by one [from HEAD]

This commit is contained in:
Florian Westphal 2006-12-17 23:00:17 +00:00
parent a915559086
commit 880d4a88b1

View File

@ -12,7 +12,7 @@
#include "array.h" #include "array.h"
static char UNUSED id[] = "$Id: array.c,v 1.11.2.1 2006/12/02 13:00:25 fw Exp $"; static char UNUSED id[] = "$Id: array.c,v 1.11.2.2 2006/12/17 23:00:17 fw Exp $";
#include <assert.h> #include <assert.h>
@ -247,19 +247,21 @@ void *
array_get(array * a, size_t membersize, size_t pos) array_get(array * a, size_t membersize, size_t pos)
{ {
size_t totalsize; size_t totalsize;
size_t posplus1 = pos + 1;
assert(membersize > 0); assert(membersize > 0);
assert(a != NULL); assert(a != NULL);
if (array_UNUSABLE(a)) if (!posplus1 || array_UNUSABLE(a))
return NULL; return NULL;
if (!safemult_sizet(pos, membersize, &totalsize)) if (!safemult_sizet(posplus1, membersize, &totalsize))
return NULL; return NULL;
if (a->allocated < totalsize) if (a->allocated < totalsize)
return NULL; return NULL;
totalsize = pos * membersize;
return a->mem + totalsize; return a->mem + totalsize;
} }