]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
verify: fix memory leak
authorAndrei Borzenkov <arvidjaar@gmail.com>
Tue, 12 Jan 2016 18:10:12 +0000 (21:10 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Tue, 12 Jan 2016 18:52:42 +0000 (21:52 +0300)
Found by: Coverity scan.
CID: 96643

grub-core/commands/verify.c

index 9620a3b4c0f407e145a184ee5d207507d709dc9b..67cb1c785095e104b874e38c0adfbad48f95ad64 100644 (file)
@@ -324,19 +324,19 @@ grub_load_public_key (grub_file_t f)
          if (grub_file_read (f, &l, sizeof (l)) != sizeof (l))
            {
              grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
-             goto fail;
+             break;
            }
          
          lb = (grub_be_to_cpu16 (l) + GRUB_CHAR_BIT - 1) / GRUB_CHAR_BIT;
          if (lb > READBUF_SIZE - sizeof (grub_uint16_t))
            {
              grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
-             goto fail;
+             break;
            }
          if (grub_file_read (f, buffer + sizeof (grub_uint16_t), lb) != (grub_ssize_t) lb)
            {
              grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
-             goto fail;
+             break;
            }
          grub_memcpy (buffer, &l, sizeof (l));
 
@@ -346,10 +346,16 @@ grub_load_public_key (grub_file_t f)
                             buffer, lb + sizeof (grub_uint16_t), 0))
            {
              grub_error (GRUB_ERR_BAD_SIGNATURE, N_("bad signature"));
-             goto fail;
+             break;
            }
        }
 
+      if (i < pkalgos[pk].nmpipub)
+       {
+         grub_free (sk);
+         goto fail;
+       }
+
       GRUB_MD_SHA1->final (fingerprint_context);
 
       grub_memcpy (sk->fingerprint, GRUB_MD_SHA1->read (fingerprint_context), 20);