]> git.pond.sub.org Git - empserver/commitdiff
Refuse to grow or truncate files with fixed size
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 4 May 2011 18:51:54 +0000 (20:51 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 25 Jun 2011 14:50:20 +0000 (16:50 +0200)
Make ef_write() treat it like any other invalid write beyond the file
size: oops.  Be less harsh in ef_extend() and ef_truncate(): log an
error.

src/lib/common/file.c

index e586d96e022c1d44ce7ba2ec7f7c2a2a367cc246..675e776fbcdde85cf099a77fa3eb478cb4c6ea8f 100644 (file)
@@ -543,6 +543,8 @@ ef_write(int type, int id, void *from)
     ep = &empfile[type];
     if (CANT_HAPPEN((ep->flags & (EFF_MEM | EFF_PRIVATE)) == EFF_PRIVATE))
        return 0;
+    if (CANT_HAPPEN(ep->nent >= 0 && id >= ep->nent))
+       return 0;               /* beyond fixed size */
     new_seqno(ep, from);
     if (id >= ep->fids) {
        /* beyond end of file */
@@ -694,6 +696,10 @@ ef_extend(int type, int count)
     if (ef_check(type) < 0)
        return 0;
     ep = &empfile[type];
+    if (ep->nent >= 0) {
+       logerror("Can't extend %s, its size is fixed", ep->name);
+       return 0;
+    }
     if (!do_extend(ep, count))
        return 0;
     if (ep->onresize)
@@ -806,6 +812,10 @@ ef_truncate(int type, int count)
     if (ef_check(type) < 0 || CANT_HAPPEN(EF_IS_VIEW(type)))
        return 0;
     ep = &empfile[type];
+    if (ep->nent >= 0) {
+       logerror("Can't truncate %s, its size is fixed", ep->name);
+       return 0;
+    }
     if (CANT_HAPPEN(count < 0 || count > ep->fids))
        return 0;