From 6c3825f2b750bf9b913c6ea986739e648c470603 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Wed, 2 Oct 2013 20:30:15 +0200 Subject: Check for negative sizes in file_set_size * libdiskfs/file-set-size.c (diskfs_S_file_set_size): Return EINVAL if size is negative. * libnetfs/file-set-size.c (netfs_S_file_set_size): Likewise. * libtreefs/s-file.c (treefs_S_file_set_size): Likewise. * storeio/io.c (trivfs_S_file_set_size): Likewise. * term/users.c (trivfs_S_file_set_size): Likewise. * trans/null.c (trivfs_S_file_set_size): Likewise. * trans/streamio.c (trivfs_S_file_set_size): Likewise. --- libdiskfs/file-set-size.c | 2 +- libnetfs/file-set-size.c | 2 ++ libtreefs/s-file.c | 2 ++ storeio/io.c | 2 ++ term/users.c | 2 ++ trans/null.c | 2 ++ trans/streamio.c | 2 ++ 7 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libdiskfs/file-set-size.c b/libdiskfs/file-set-size.c index 18abb469..fe2125ae 100644 --- a/libdiskfs/file-set-size.c +++ b/libdiskfs/file-set-size.c @@ -26,7 +26,7 @@ diskfs_S_file_set_size (struct protid *cred, { CHANGE_NODE_FIELD (cred, ({ - if (!(cred->po->openstat & O_WRITE)) + if (!(cred->po->openstat & O_WRITE) || (size < 0)) err = EINVAL; else if (size < np->dn_stat.st_size) { diff --git a/libnetfs/file-set-size.c b/libnetfs/file-set-size.c index 72f31db7..b4a8cd23 100644 --- a/libnetfs/file-set-size.c +++ b/libnetfs/file-set-size.c @@ -29,6 +29,8 @@ netfs_S_file_set_size (struct protid *user, if (!user) return EOPNOTSUPP; + else if (size < 0) + return EINVAL; pthread_mutex_lock (&user->po->np->lock); err = netfs_attempt_set_size (user->user, user->po->np, size); diff --git a/libtreefs/s-file.c b/libtreefs/s-file.c index 73c32d7f..c24d645e 100644 --- a/libtreefs/s-file.c +++ b/libtreefs/s-file.c @@ -220,6 +220,8 @@ treefs_S_file_set_size (struct treefs_protid *cred, off_t size) { if (!cred) return EOPNOTSUPP; + else if (size < 0) + return EINVAL; return treefs_s_file_set_size (cred, size); } diff --git a/storeio/io.c b/storeio/io.c index c79f6ba3..eaa20def 100644 --- a/storeio/io.c +++ b/storeio/io.c @@ -178,6 +178,8 @@ trivfs_S_file_set_size (struct trivfs_protid *cred, { if (! cred) return EOPNOTSUPP; + else if (size < 0) + return EINVAL; else return 0; } diff --git a/term/users.c b/term/users.c index 9d745c6d..eacd150a 100644 --- a/term/users.c +++ b/term/users.c @@ -1808,6 +1808,8 @@ trivfs_S_file_set_size (struct trivfs_protid *cred, { if (!cred) return EOPNOTSUPP; + else if (size < 0) + return EINVAL; pthread_mutex_lock (&global_lock); if ((cred->po->openmodes & O_WRITE) == 0) { diff --git a/trans/null.c b/trans/null.c index 8b3b4e0f..4828cce3 100644 --- a/trans/null.c +++ b/trans/null.c @@ -245,6 +245,8 @@ trivfs_S_file_set_size (struct trivfs_protid *cred, mach_port_t reply, mach_msg_type_name_t replytype, loff_t size) { + if (size < 0) + return EINVAL; return 0; } diff --git a/trans/streamio.c b/trans/streamio.c index 8ff3dc63..68badd21 100644 --- a/trans/streamio.c +++ b/trans/streamio.c @@ -625,6 +625,8 @@ trivfs_S_file_set_size (struct trivfs_protid *cred, return EOPNOTSUPP; else if (!(cred->po->openmodes & O_WRITE)) return EBADF; + else if (size < 0) + return EINVAL; else return 0; } -- cgit v1.2.3