From 3be9febdf9ecabd9144ceb5181d8144f69e44fb6 Mon Sep 17 00:00:00 2001 From: "Claire J. In" Date: Fri, 29 Mar 2019 12:16:04 -0700 Subject: [PATCH] lib/ftl: check for null Fixes #726. This prevents a segmentation fault by checking the pointer before accessing it. Change-Id: I18a3776fbcd6242c6efd1b88044debaa88c7342f Signed-off-by: Claire J. In Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449591 Reviewed-by: wuzhouhui Reviewed-by: Konrad Sztyber Reviewed-by: Shuhei Matsumoto Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- lib/ftl/ftl_io.c | 4 ++++ lib/ftl/ftl_reloc.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/ftl/ftl_io.c b/lib/ftl/ftl_io.c index bfed8374c..4b952b04d 100644 --- a/lib/ftl/ftl_io.c +++ b/lib/ftl/ftl_io.c @@ -256,6 +256,10 @@ ftl_io_erase_init(struct ftl_band *band, size_t lbk_cnt, spdk_ftl_fn cb) }; io = ftl_io_init_internal(&opts); + if (!io) { + return NULL; + } + io->lbk_cnt = lbk_cnt; return io; diff --git a/lib/ftl/ftl_reloc.c b/lib/ftl/ftl_reloc.c index 412de3d9d..a38052eef 100644 --- a/lib/ftl/ftl_reloc.c +++ b/lib/ftl/ftl_reloc.c @@ -454,7 +454,13 @@ ftl_reloc_io_init(struct ftl_band_reloc *breloc, struct ftl_io *io, } io = ftl_io_init_internal(&opts); + if (!io) { + spdk_dma_free(opts.data); + return -1; + } + io->ppa = ppa; + return 0; }