[hackers] [wmii] Fix that pesky bug related to open Fids of objects which don't exist anymore.

From: Kris Maglione <jg_AT_suckless.org>
Date: Wed Feb 21 04:15:32 2007

changeset: 1920:3a37ee863d8d
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Feb 20 22:11:40 2007 -0500
summary: Fix that pesky bug related to open Fids of objects which don't exist anymore.

diff -r 9b4b0d2e77a9 -r 3a37ee863d8d fs.c
--- a/fs.c Tue Feb 20 21:12:37 2007 -0500
+++ b/fs.c Tue Feb 20 22:11:40 2007 -0500
@@ -481,6 +481,22 @@ LastItem:
         return ret;
 }
 
+Bool
+verify_file(FileId *f) {
+ FileId *nf;
+
+ if(!f)
+ return True;
+ if(verify_file(f->next)) {
+ nf = lookup_file(f->next, f->tab.name);
+ if(nf) {
+ free_file(nf);
+ return True;
+ }
+ }
+ return False;
+}
+
 /* Service Functions */
 /*********************/
 void
@@ -568,8 +584,14 @@ fs_stat(P9Req *r) {
         Stat s;
         int size;
         uchar *buf;
-
- dostat(&s, fs_size(r->fid->aux), r->fid->aux);
+ FileId *f = r->fid->aux;
+
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
+ dostat(&s, fs_size(f), f);
         r->ofcall.nstat = size = ixp_sizeof_stat(&s);
         buf = emallocz(size);
         r->ofcall.stat = buf;
@@ -586,6 +608,12 @@ fs_read(P9Req *r) {
 
         offset = 0;
         f = r->fid->aux;
+
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
         if(f->tab.perm & P9DMDIR && f->tab.perm & 0400) {
                 Stat s;
                 offset = 0;
@@ -683,6 +711,12 @@ fs_write(P9Req *r) {
                 return;
         }
         f = r->fid->aux;
+
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
         switch(f->tab.type) {
         case FsFColRules:
         case FsFTagRules:
@@ -762,6 +796,11 @@ fs_open(P9Req *r) {
         FidLink *fl;
         FileId *f = r->fid->aux;
 
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
         switch(f->tab.type) {
         case FsFEvent:
                 fl = emallocz(sizeof(FidLink));
@@ -822,6 +861,12 @@ fs_remove(P9Req *r) {
 fs_remove(P9Req *r) {
         FileId *f = r->fid->aux;
 
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
+
         switch(f->tab.type) {
         default:
                 /* XXX: This should be taken care of by the library */
@@ -842,6 +887,12 @@ fs_clunk(P9Req *r) {
         char *buf;
         int i;
         FileId *f = r->fid->aux;
+
+ if(!verify_file(f)) {
+ respond(r, Enofile);
+ return;
+ }
+
 
         switch(f->tab.type) {
         case FsFColRules:
Received on Wed Feb 21 2007 - 04:15:32 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:35 UTC