Whamcloud - gitweb
e2fsck: avoid theoretical null dereference in end_problem_latch()
authorzhanchengbin <zhanchengbin1@huawei.com>
Fri, 31 Dec 2021 07:43:10 +0000 (15:43 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 12 May 2022 00:56:42 +0000 (20:56 -0400)
This should only happen if there is a programming bug, but better safe
than sorry.

Link: https://lore.kernel.org/r/9a9c6658-a8b3-794a-85df-c3bdf0470111@huawei.com
Signed-off-by: zhanchengbin <zhanchengbin1@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/problem.c

index 46a7427..95f0ace 100644 (file)
@@ -2321,6 +2321,8 @@ int end_problem_latch(e2fsck_t ctx, int mask)
        int answer = -1;
 
        ldesc = find_latch(mask);
+       if (!ldesc)
+               return answer;
        if (ldesc->end_message && (ldesc->flags & PRL_LATCHED)) {
                clear_problem_context(&pctx);
                answer = fix_problem(ctx, ldesc->end_message, &pctx);
@@ -2467,8 +2469,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
         * Do special latch processing.  This is where we ask the
         * latch question, if it exists
         */
-       if (ptr->flags & PR_LATCH_MASK) {
-               ldesc = find_latch(ptr->flags & PR_LATCH_MASK);
+       if (ptr->flags & PR_LATCH_MASK &&
+           (ldesc = find_latch(ptr->flags & PR_LATCH_MASK)) != NULL) {
                if (ldesc->question && !(ldesc->flags & PRL_LATCHED)) {
                        ans = fix_problem(ctx, ldesc->question, pctx);
                        if (ans == 1)