diff mbox

btrfs: filter invalid arg for btrfs resize

Message ID 1396260206-14153-1-git-send-email-guihc.fnst@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Gui Hecheng March 31, 2014, 10:03 a.m. UTC
Originally following cmds will work:
	# btrfs fi resize -10A  <mnt>
	# btrfs fi resize -10Gaha <mnt>
Filter the arg by checking the return pointer of memparse.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 fs/btrfs/ioctl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

David Sterba April 4, 2014, 12:13 p.m. UTC | #1
On Mon, Mar 31, 2014 at 06:03:25PM +0800, Gui Hecheng wrote:
> Originally following cmds will work:
> 	# btrfs fi resize -10A  <mnt>
> 	# btrfs fi resize -10Gaha <mnt>
> Filter the arg by checking the return pointer of memparse.

This should probably also go to stable@

> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
> ---
>  fs/btrfs/ioctl.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index e174770..2ed21fa 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1459,6 +1459,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
>  	struct btrfs_trans_handle *trans;
>  	struct btrfs_device *device = NULL;
>  	char *sizestr;
> +	char *retptr;

Minor nit, the variable is otherwise unused, it's better to put it into
the enclosing statement block with memparse.

>  	char *devstr = NULL;
>  	int ret = 0;
>  	int mod = 0;
> @@ -1526,8 +1527,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
>  			mod = 1;
>  			sizestr++;
>  		}
> -		new_size = memparse(sizestr, NULL);
> -		if (new_size == 0) {
> +		new_size = memparse(sizestr, &retptr);
> +		if (*retptr != '\0' || new_size == 0) {
>  			ret = -EINVAL;
>  			goto out_free;
>  		}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index e174770..2ed21fa 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1459,6 +1459,7 @@  static noinline int btrfs_ioctl_resize(struct file *file,
 	struct btrfs_trans_handle *trans;
 	struct btrfs_device *device = NULL;
 	char *sizestr;
+	char *retptr;
 	char *devstr = NULL;
 	int ret = 0;
 	int mod = 0;
@@ -1526,8 +1527,8 @@  static noinline int btrfs_ioctl_resize(struct file *file,
 			mod = 1;
 			sizestr++;
 		}
-		new_size = memparse(sizestr, NULL);
-		if (new_size == 0) {
+		new_size = memparse(sizestr, &retptr);
+		if (*retptr != '\0' || new_size == 0) {
 			ret = -EINVAL;
 			goto out_free;
 		}