X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fodr_mem.c;h=9d502dfa59478962d71913940c6ffbe74d78dda9;hp=28181e323d058db2f5fb3163896fc70b63bbb5ad;hb=ffc8ea2eb23fe8c74fbeb96d05b31c477767923f;hpb=833bf58328945361db8a744c0dec2c925c97d43a diff --git a/src/odr_mem.c b/src/odr_mem.c index 28181e3..9d502df 100644 --- a/src/odr_mem.c +++ b/src/odr_mem.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2013 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** @@ -10,6 +10,7 @@ #include #endif +#include #include #include "odr-priv.h" #include @@ -65,8 +66,7 @@ size_t odr_total(ODR o) Odr_oct *odr_create_Odr_oct(ODR o, const char *buf, int sz) { Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct)); - p->buf = (char *) odr_malloc(o, sz); - memcpy(p->buf, buf, sz); + p->buf = odr_strdupn(o, buf, sz); p->len = sz; return p; } @@ -97,6 +97,11 @@ int odr_grow_block(ODR b, int min_bytes) int odr_write(ODR o, const char *buf, int bytes) { + if (bytes < 0 || o->op->pos > INT_MAX - bytes) + { + odr_seterror(o, OSPACE, 40); + return -1; + } if (o->op->pos + bytes >= o->op->size && odr_grow_block(o, bytes)) { odr_seterror(o, OSPACE, 40);