projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bundle sha1 rather than use libgcrypt/nettle
[yaz-moved-to-github.git]
/
src
/
odr_mem.c
diff --git
a/src/odr_mem.c
b/src/odr_mem.c
index
690477d
..
9d502df
100644
(file)
--- a/
src/odr_mem.c
+++ b/
src/odr_mem.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
/**
* See the file LICENSE for details.
*/
/**
@@
-10,6
+10,7
@@
#include <config.h>
#endif
#include <config.h>
#endif
+#include <limits.h>
#include <stdlib.h>
#include "odr-priv.h"
#include <yaz/xmalloc.h>
#include <stdlib.h>
#include "odr-priv.h"
#include <yaz/xmalloc.h>
@@
-65,9
+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));
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 + 1);
- memcpy(p->buf, buf, sz);
- p->buf[sz] = '\0';
+ p->buf = odr_strdupn(o, buf, sz);
p->len = sz;
return p;
}
p->len = sz;
return p;
}
@@
-98,6
+97,11
@@
int odr_grow_block(ODR b, int min_bytes)
int odr_write(ODR o, const char *buf, int 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);
if (o->op->pos + bytes >= o->op->size && odr_grow_block(o, bytes))
{
odr_seterror(o, OSPACE, 40);