From 77a7da57886543b363b60f692c4fd0a65733c3a1 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 24 Jan 2003 20:56:50 +0000 Subject: [PATCH] Defined MAX_ATTR_SIZE and added checks to obj_write() to enforce it. --- lib/object.c | 6 ++++-- lib/object.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/object.c b/lib/object.c index 0c5f88bd..6f047863 100644 --- a/lib/object.c +++ b/lib/object.c @@ -47,7 +47,7 @@ obj_new(struct mempool *pool) int obj_read(struct fastbuf *f, struct odes *o) { - byte buf[1024]; + byte buf[MAX_ATTR_SIZE]; while (bgets(f, buf, sizeof(buf))) { @@ -64,8 +64,9 @@ obj_write(struct fastbuf *f, struct odes *d) for(struct oattr *a=d->attrs; a; a=a->next) for(struct oattr *b=a; b; b=b->same) { + byte *z; bputc(f, a->attr); - for(byte *z = b->val; *z; z++) + for(z = b->val; *z; z++) if (*z >= ' ' || *z == '\t') bputc(f, *z); else @@ -73,6 +74,7 @@ obj_write(struct fastbuf *f, struct odes *d) bputc(f, '?'); log(L_ERROR, "obj_dump: Found non-ASCII characters (URL might be %s)", obj_find_aval(d, 'U')); } + ASSERT(z - b->val <= MAX_ATTR_SIZE-2); bputc(f, '\n'); } } diff --git a/lib/object.h b/lib/object.h index 01da6ab9..d7d7efaa 100644 --- a/lib/object.h +++ b/lib/object.h @@ -10,6 +10,8 @@ #ifndef _SHERLOCK_OBJECT_H #define _SHERLOCK_OBJECT_H +#define MAX_ATTR_SIZE 1024 /* Maximum length an attribute can ever have (including name and trailing 0) */ + struct fastbuf; struct odes { /* Object description */ -- 2.39.2