]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: fix label parsing and validation
authorDarrick J. Wong <darrick.wong@oracle.com>
Fri, 26 Apr 2019 20:40:10 +0000 (15:40 -0500)
committerEric Sandeen <sandeen@redhat.com>
Fri, 26 Apr 2019 20:40:10 +0000 (15:40 -0500)
When we're trying to set a new label, check the length to make sure we
won't overflow the label size, and size label[] so that we can use
strncpy without static checker complaints.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/label.c

index 602ece8961717ce6c675c9b9af4b2bf72763b01e..72e07964896d492006a12a0a291f970552ee1b78 100644 (file)
@@ -40,7 +40,7 @@ label_f(
 {
        int             c;
        int             error;
-       char            label[FSLABEL_MAX];
+       char            label[FSLABEL_MAX + 1];
 
        if (argc == 1) {
                memset(label, 0, sizeof(label));
@@ -54,7 +54,13 @@ label_f(
                        label[0] = '\0';
                        break;
                case 's':
-                       strncpy(label, optarg, sizeof(label));
+                       if (strlen(optarg) > FSLABEL_MAX) {
+                               errno = EINVAL;
+                               error = 1;
+                               goto out;
+                       }
+                       strncpy(label, optarg, sizeof(label) - 1);
+                       label[sizeof(label) - 1] = 0;
                        break;
                default:
                        return command_usage(&label_cmd);