]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
bcache: Strip endline when writing the label through sysfs
authorGabriel de Perthuis <g2p.code@gmail.com>
Fri, 12 Jul 2013 11:35:44 +0000 (13:35 +0200)
committerKent Overstreet <kmo@daterainc.com>
Fri, 26 Jul 2013 20:15:48 +0000 (13:15 -0700)
sysfs attributes with unusual characters have crappy failure modes
in Squeeze (udev 164); later versions of udev are unaffected.

This should make these characters more unusual.

Signed-off-by: Gabriel de Perthuis <g2p.code@gmail.com>
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
drivers/md/bcache/sysfs.c

index 12a2c2846f994a1e2d51bf79374426df96893418..a87fbb5a093f250cb8f6a30d32efbfdaa16f9b3f 100644 (file)
@@ -223,8 +223,13 @@ STORE(__cached_dev)
        }
 
        if (attr == &sysfs_label) {
-               /* note: endlines are preserved */
-               memcpy(dc->sb.label, buf, SB_LABEL_SIZE);
+               if (size > SB_LABEL_SIZE)
+                       return -EINVAL;
+               memcpy(dc->sb.label, buf, size);
+               if (size < SB_LABEL_SIZE)
+                       dc->sb.label[size] = '\0';
+               if (size && dc->sb.label[size - 1] == '\n')
+                       dc->sb.label[size - 1] = '\0';
                bch_write_bdev_super(dc, NULL);
                if (dc->disk.c) {
                        memcpy(dc->disk.c->uuids[dc->disk.id].label,