summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@gnu.org>2006-06-15 13:55:27 +0000
committerThomas Schwinge <tschwinge@gnu.org>2006-06-15 13:55:27 +0000
commitb1989af0015f6748552744cff474dc55db83176b (patch)
tree4c0a76f85b4dace66ecb41d8085f19b45208ef91
parent95b1426fb75a5458ac15d28a04501327875fa58d (diff)
2006-06-15 Thomas Schwinge <tschwinge@gnu.org>
* io-seek.c (netfs_S_io_seek): Return EINVAL if file pointer would become negative.
-rw-r--r--libnetfs/ChangeLog5
-rw-r--r--libnetfs/io-seek.c28
2 files changed, 17 insertions, 16 deletions
diff --git a/libnetfs/ChangeLog b/libnetfs/ChangeLog
index 6b9d9d64..da9b28c9 100644
--- a/libnetfs/ChangeLog
+++ b/libnetfs/ChangeLog
@@ -1,3 +1,8 @@
+2006-06-15 Thomas Schwinge <tschwinge@gnu.org>
+
+ * io-seek.c (netfs_S_io_seek): Return EINVAL if file pointer would
+ become negative.
+
2004-09-12 Marco Gerards <metgerards@student.han.nl>
* io-select.c: Include <hurd/ports.h>.
diff --git a/libnetfs/io-seek.c b/libnetfs/io-seek.c
index 401c5004..85408a4d 100644
--- a/libnetfs/io-seek.c
+++ b/libnetfs/io-seek.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 2000, 2006 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
@@ -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;
}