Whamcloud - gitweb
LU-2394 llog: Fix a NULL pointer dereference
authorPrakash Surya <surya1@llnl.gov>
Mon, 26 Nov 2012 23:54:15 +0000 (15:54 -0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 29 Nov 2012 00:27:23 +0000 (19:27 -0500)
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 <surya1@llnl.gov>
Change-Id: I949b558d0ea4569685e8ed85b7a920b2dca548c3
Reviewed-on: http://review.whamcloud.com/4676
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Mike Pershin <tappro@whamcloud.com>
lustre/obdclass/llog_cat.c

index cc065c1..47266b2 100644 (file)
@@ -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;