Skip to content

Commit c5b430e

Browse files
ebiggersgregkh
authored andcommitted
elevator: fix truncation of icq_cache_name
commit 9bd2bbc upstream. gcc 7.1 reports the following warning: block/elevator.c: In function ‘elv_register’: block/elevator.c:898:5: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] "%s_io_cq", e->elevator_name); ^~~~~~~~~~ block/elevator.c:897:3: note: ‘snprintf’ output between 7 and 22 bytes into a destination of size 21 snprintf(e->icq_cache_name, sizeof(e->icq_cache_name), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "%s_io_cq", e->elevator_name); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The bug is that the name of the icq_cache is 6 characters longer than the elevator name, but only ELV_NAME_MAX + 5 characters were reserved for it --- so in the case of a maximum-length elevator name, the 'q' character in "_io_cq" would be truncated by snprintf(). Fix it by reserving ELV_NAME_MAX + 6 characters instead. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Bart Van Assche <Bart.VanAssche@sandisk.com> Signed-off-by: Jens Axboe <axboe@fb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3941d33 commit c5b430e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

include/linux/elevator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct elevator_type
9797
struct module *elevator_owner;
9898

9999
/* managed by elevator core */
100-
char icq_cache_name[ELV_NAME_MAX + 5]; /* elvname + "_io_cq" */
100+
char icq_cache_name[ELV_NAME_MAX + 6]; /* elvname + "_io_cq" */
101101
struct list_head list;
102102
};
103103

0 commit comments

Comments
 (0)