From e6ea6e70cd91f01334957f421b5692dbaa6ad75b Mon Sep 17 00:00:00 2001 From: Prakash Surya Date: Mon, 26 Nov 2012 15:54:15 -0800 Subject: [PATCH] LU-2394 llog: Fix a NULL pointer dereference If llog_cat_id2handle fails and returns a positive value, it may free its 'res' parameter and set it to NULL. Thus, a caller must be cautious not to cause a NULL pointer dereference on error. This patch fixes the cat_cancel_cb function, keeping it from dereferencing this potentially NULL pointer. In addition, any console message regarding a failed call to llog_cat_id2handle in llog_cat.c now outputs the same message. Signed-off-by: Prakash Surya Change-Id: I949b558d0ea4569685e8ed85b7a920b2dca548c3 Reviewed-on: http://review.whamcloud.com/4676 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Mike Pershin --- lustre/obdclass/llog_cat.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lustre/obdclass/llog_cat.c b/lustre/obdclass/llog_cat.c index cc065c1..47266b2 100644 --- a/lustre/obdclass/llog_cat.c +++ b/lustre/obdclass/llog_cat.c @@ -510,7 +510,9 @@ int llog_cat_cancel_records(const struct lu_env *env, rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl); if (rc) { - CERROR("Cannot find log "LPX64"\n", lgl->lgl_oid); + CERROR("%s: cannot find handle for llog "LPX64": %d\n", + cathandle->lgh_ctxt->loc_obd->obd_name, + lgl->lgl_oid, rc); break; } @@ -565,11 +567,12 @@ int llog_cat_process_cb(const struct lu_env *env, struct llog_handle *cat_llh, rec->lrh_index, cat_llh->lgh_id.lgl_oid); rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id); - if (rc) { - CERROR("Cannot find handle for log "LPX64"\n", - lir->lid_id.lgl_oid); - RETURN(rc); - } + if (rc) { + CERROR("%s: cannot find handle for llog "LPX64": %d\n", + cat_llh->lgh_ctxt->loc_obd->obd_name, + lir->lid_id.lgl_oid, rc); + RETURN(rc); + } if (rec->lrh_index < d->lpd_startcat) /* Skip processing of the logs until startcat */ @@ -726,11 +729,12 @@ static int llog_cat_reverse_process_cb(const struct lu_env *env, le32_to_cpu(rec->lrh_index), cat_llh->lgh_id.lgl_oid); rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id); - if (rc) { - CERROR("Cannot find handle for log "LPX64"\n", - lir->lid_id.lgl_oid); - RETURN(rc); - } + if (rc) { + CERROR("%s: cannot find handle for llog "LPX64": %d\n", + cat_llh->lgh_ctxt->loc_obd->obd_name, + lir->lid_id.lgl_oid, rc); + RETURN(rc); + } rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL); RETURN(rc); @@ -830,8 +834,8 @@ int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle, rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id); if (rc) { - CERROR("%s: cannot find handle for llog "LPX64"\n: %d", - loghandle->lgh_ctxt->loc_obd->obd_name, + CERROR("%s: cannot find handle for llog "LPX64": %d\n", + cathandle->lgh_ctxt->loc_obd->obd_name, lir->lid_id.lgl_oid, rc); if (rc == -ENOENT || rc == -ESTALE) { index = rec->lrh_index; -- 1.8.3.1