Skip to content

Commit aee6f1c

Browse files
g2ptorvalds
authored andcommitted
bcache: Strip endline when writing the label through sysfs
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 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6d9d21e commit aee6f1c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎drivers/md/bcache/sysfs.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ STORE(__cached_dev)
223223
}
224224

225225
if (attr == &sysfs_label) {
226-
/* note: endlines are preserved */
227-
memcpy(dc->sb.label, buf, SB_LABEL_SIZE);
226+
if (size > SB_LABEL_SIZE)
227+
return -EINVAL;
228+
memcpy(dc->sb.label, buf, size);
229+
if (size < SB_LABEL_SIZE)
230+
dc->sb.label[size] = '\0';
231+
if (size && dc->sb.label[size - 1] == '\n')
232+
dc->sb.label[size - 1] = '\0';
228233
bch_write_bdev_super(dc, NULL);
229234
if (dc->disk.c) {
230235
memcpy(dc->disk.c->uuids[dc->disk.id].label,

0 commit comments

Comments
 (0)