Block: Fix block/elevator.c elevator_get() off-by-one error
authorwzt.wzt@gmail.com <wzt.wzt@gmail.com>
Fri, 2 Apr 2010 06:41:14 +0000 (08:41 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 2 Apr 2010 06:41:14 +0000 (08:41 +0200)
elevator_get() not check the name length, if the name length > sizeof(elv),
elv will miss the '\0'. And elv buffer will be replace "-iosched" as something
like aaaaaaaaa, then call request_module() can load an not trust module.

Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
block/elevator.c

index df75676f6671ea97e33b78567dae2fbfb0f75058..76e3702d53817e4aee08d092a59f07ca840145cc 100644 (file)
@@ -154,7 +154,7 @@ static struct elevator_type *elevator_get(const char *name)
 
                spin_unlock(&elv_list_lock);
 
-               sprintf(elv, "%s-iosched", name);
+               snprintf(elv, sizeof(elv), "%s-iosched", name);
 
                request_module("%s", elv);
                spin_lock(&elv_list_lock);