]> mj.ucw.cz Git - libucw.git/commitdiff
Defined MAX_ATTR_SIZE and added checks to obj_write() to enforce it.
authorMartin Mares <mj@ucw.cz>
Fri, 24 Jan 2003 20:56:50 +0000 (20:56 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 24 Jan 2003 20:56:50 +0000 (20:56 +0000)
lib/object.c
lib/object.h

index 0c5f88bd76d1a6b32d9ca244207bfc40690b0ce2..6f047863086bd508c4c8242d10895fd3c86a1d3b 100644 (file)
@@ -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');
       }
 }
index 01da6ab9e8aa1749fea578d54a6d717558343f5b..d7d7efaaa03ce5a9ea5e91d0739bcfec6ce27053 100644 (file)
@@ -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 */