From 57eee18288f8ed8a6aa8cf51e6eeba32d1b4231f Mon Sep 17 00:00:00 2001 From: yidong0635 Date: Mon, 21 Mar 2022 12:32:22 +0800 Subject: [PATCH] blobfs: Add missing error checks for strdup. Here were some cases for file->name using strdup missing check for no memory, but some had. So add them. Signed-off-by: yidong0635 Change-Id: I91feeea3711f127135aedf37e53624811a4ab5e8 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11989 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Changpeng Liu --- lib/blobfs/blobfs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index f7b14619f..ca10a8865 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -750,6 +750,14 @@ iter_cb(void *ctx, struct spdk_blob *blob, int rc) } f->name = strdup(name); + if (!f->name) { + SPDK_ERRLOG("Cannot allocate memory for file name\n"); + args->fn.fs_op_with_handle(args->arg, fs, -ENOMEM); + free_fs_request(req); + file_free(f); + return; + } + f->blobid = spdk_blob_get_id(blob); f->length = *length; f->length_flushed = *length; @@ -1350,6 +1358,13 @@ _fs_md_rename_file(struct spdk_fs_request *req) free(f->name); f->name = strdup(args->op.rename.new_name); + if (!f->name) { + SPDK_ERRLOG("Cannot allocate memory for file name\n"); + args->fn.fs_op(args->arg, -ENOMEM); + free_fs_request(req); + return; + } + args->file = f; spdk_bs_open_blob(args->fs->bs, f->blobid, fs_rename_blob_open_cb, req); }