Fix segmentation fault while specifying clustername with rbd engine
authorJevon Qiao <scaleqiao@gmail.com>
Thu, 28 Jul 2016 07:22:40 +0000 (15:22 +0800)
committerJevon Qiao <scaleqiao@gmail.com>
Thu, 28 Jul 2016 07:22:40 +0000 (15:22 +0800)
Fio with rbd engine will panic if clustername option is specified but clientname
is not. In that case, o->client_name will be a NULL pointer, strlen(o->client_name) in _fio_rbd_connect() will lead to the segmentation fault.

Signed-off-by: Jevon Qiao <scaleqiao@gmail.com>
engines/rbd.c

index 7a109eedf3d62ed1978cecd9fe74e0799962bafb..c5abd2d22629a89dd3450e29f231603861a427bc 100644 (file)
@@ -131,15 +131,18 @@ static int _fio_rbd_connect(struct thread_data *td)
                char *client_name = NULL; 
 
                /*
                char *client_name = NULL; 
 
                /*
-                * If we specify cluser name, the rados_creat2
+                * If we specify cluser name, the rados_create2
                 * will not assume 'client.'. name is considered
                 * as a full type.id namestr
                 */
                 * will not assume 'client.'. name is considered
                 * as a full type.id namestr
                 */
-               if (!index(o->client_name, '.')) {
-                       client_name = calloc(1, strlen("client.") +
-                                               strlen(o->client_name) + 1);
-                       strcat(client_name, "client.");
-                       o->client_name = strcat(client_name, o->client_name);
+               if (o->client_name) {
+                       if (!index(o->client_name, '.')) {
+                               client_name = calloc(1, strlen("client.") +
+                                                   strlen(o->client_name) + 1);
+                               strcat(client_name, "client.");
+                               o->client_name = strcat(client_name,
+                                                       o->client_name);
+                       }
                }
                r = rados_create2(&rbd->cluster, o->cluster_name,
                                        o->client_name, 0);
                }
                r = rados_create2(&rbd->cluster, o->cluster_name,
                                        o->client_name, 0);