bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] Disallow seeking into the negative


From: Thomas Schwinge
Subject: [patch] Disallow seeking into the negative
Date: Sun, 4 Jun 2006 13:52:51 -0400
User-agent: Mutt/1.5.6+20040907i

Hello!

Some time ago Roland committed the following:

#v+
2006-03-05  Roland McGrath  <roland@frob.com>

        * io-seek.c (diskfs_S_io_seek): Return EINVAL if file pointer would
        become negative.

Index: libdiskfs/io-seek.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libdiskfs/io-seek.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -p -b -r1.7 -r1.8
--- libdiskfs/io-seek.c 18 Jul 2000 21:33:33 -0000      1.7
+++ libdiskfs/io-seek.c 5 Mar 2006 11:47:36 -0000       1.8
@@ -39,20 +39,22 @@ diskfs_S_io_seek (struct protid *cred,
   iohelp_get_conch (&np->conch);
   switch (whence)
     {
-    case SEEK_SET:
-      cred->po->filepointer = offset;
-      break;
     case SEEK_CUR:
-      cred->po->filepointer += offset;
-      break;
+      offset += cred->po->filepointer;
+      goto check;
     case SEEK_END:
-      cred->po->filepointer = (np->dn_stat.st_size + offset);
+      offset += np->dn_stat.st_size;
+    case SEEK_SET:
+    check:
+      if (offset >= 0)
+       {
+         *newoffset = cred->po->filepointer = offset;
       break;
+       }
     default:
       err = EINVAL;
       break;
     }
-  *newoffset = cred->po->filepointer;
 
   mutex_unlock (&np->lock);
   return err;
#v-


Here are the equivalent changes for the other places where seeking into
the negative might happen.  Please review.

#v+
2006-06-04  Thomas Schwinge  <tschwinge@gnu.org>

        * io-seek.c (netfs_S_io_seek): Return EINVAL if file pointer would
        become negative.

Index: libnetfs/io-seek.c
===================================================================
RCS file: /cvsroot/hurd/hurd/libnetfs/io-seek.c,v
retrieving revision 1.7
diff -u -p -r1.7 io-seek.c
--- libnetfs/io-seek.c  30 Dec 2000 18:22:28 -0000      1.7
+++ libnetfs/io-seek.c  4 Jun 2006 17:39:32 -0000
@@ -28,23 +28,16 @@ netfs_S_io_seek (struct protid *user,
                 int whence,
                 off_t *newoffset)
 {
-  error_t err;
+  error_t err = 0;
 
   if (!user)
     return EOPNOTSUPP;
 
   switch (whence)
     {
-    case SEEK_SET:
-      err = 0;
-      user->po->filepointer = offset;
-      break;
-
     case SEEK_CUR:
-      err = 0;
-      user->po->filepointer += offset;
-      break;
-      
+      offset += user->po->filepointer;
+      goto check;
     case SEEK_END:
       {
         struct node *np;
@@ -54,19 +47,22 @@ netfs_S_io_seek (struct protid *user,
 
         err = netfs_validate_stat (np, user->user);
         if (!err)
-         user->po->filepointer = np->nn_stat.st_size + offset;
+         offset += np->nn_stat.st_size;
 
         mutex_unlock (&np->lock);
-
-        break;
       }
-      
+    case SEEK_SET:
+    check:
+      if (offset >= 0)
+       {
+         *newoffset = user->po->filepointer = offset;
+         break;
+       }
     default:
       err = EINVAL;
       break;
     }
 
-  *newoffset = user->po->filepointer;
   return err;
 }
#v-
 
#v+
2006-06-04  Thomas Schwinge  <tschwinge@gnu.org>

        * open.c (open_seek): Return EINVAL if file pointer would become
        negative.

Index: storeio/open.c
===================================================================
RCS file: /cvsroot/hurd/hurd/storeio/open.c,v
retrieving revision 1.2
diff -u -p -r1.2 open.c
--- storeio/open.c      23 Sep 1996 19:58:26 -0000      1.2
+++ storeio/open.c      4 Jun 2006 17:39:33 -0000
@@ -105,19 +105,22 @@ open_seek (struct open *open, off_t offs
 
   switch (whence)
     {
-    case SEEK_SET:
-      open->offs = offs; break;
     case SEEK_CUR:
-      open->offs += offs; break;
+      offs += open->offs;
+      goto check;
     case SEEK_END:
-      open->offs = open->dev->store->size - offs; break;
+      offs += open->dev->store->size;
+    case SEEK_SET:
+    check:
+      if (offs >= 0)
+       {
+         *new_offs = open->offs = offs;
+         break;
+       }
     default:
       err = EINVAL;
     }
 
-  if (! err)
-    *new_offs = open->offs;
-
   mutex_unlock (&open->lock);
 
   return err;
#v-

#v+
2006-06-04  Thomas Schwinge  <tschwinge@gnu.org>

        * hello-mt.c (trivfs_S_io_seek): Return EINVAL if file pointer would
        become negative.
        * hello.c (trivfs_S_io_seek): Likewise.

Index: trans/hello-mt.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/hello-mt.c,v
retrieving revision 1.4
diff -u -p -r1.4 hello-mt.c
--- trans/hello-mt.c    13 Jun 2002 21:26:39 -0000      1.4
+++ trans/hello-mt.c    4 Jun 2006 17:39:33 -0000
@@ -195,19 +195,22 @@ trivfs_S_io_seek (struct trivfs_protid *
 
   switch (whence)
     {
-    case SEEK_SET:
-      op->offs = offs; break;
     case SEEK_CUR:
-      op->offs += offs; break;
+      offs += op->offs;
+      goto check;
     case SEEK_END:
-      op->offs = contents_len - offs; break;
+      offs += contents_len;
+    case SEEK_SET:
+    check:
+      if (offs >= 0)
+       {
+         *new_offs = op->offs = offs;
+         break;
+       }
     default:
       err = EINVAL;
     }
 
-  if (! err)
-    *new_offs = op->offs;
-
   mutex_unlock (&op->lock);
 
   return err;
Index: trans/hello.c
===================================================================
RCS file: /cvsroot/hurd/hurd/trans/hello.c,v
retrieving revision 1.5
diff -u -p -r1.5 hello.c
--- trans/hello.c       13 Jun 2002 21:26:39 -0000      1.5
+++ trans/hello.c       4 Jun 2006 17:39:33 -0000
@@ -171,19 +171,22 @@ trivfs_S_io_seek (struct trivfs_protid *
   op = cred->po->hook;
   switch (whence)
     {
-    case SEEK_SET:
-      op->offs = offs; break;
     case SEEK_CUR:
-      op->offs += offs; break;
+      offs += op->offs;
+      goto check;
     case SEEK_END:
-      op->offs = contents_len - offs; break;
+      offs += contents_len;
+    case SEEK_SET:
+    check:
+      if (offs >= 0)
+       {
+         *new_offs = op->offs = offs;
+         break;
+       }
     default:
       err = EINVAL;
     }
 
-  if (! err)
-    *new_offs = op->offs;
-
   return err;
 }
 
#v-


Regards,
 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]