37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From ee25c1be953bf385caf23f96384a9834c1f1c250 Mon Sep 17 00:00:00 2001
 | |
| From: "Richard W.M. Jones" <rjones@redhat.com>
 | |
| Date: Tue, 12 Jul 2022 18:10:30 +0100
 | |
| Subject: [PATCH] luks: Avoid memory leak on error path
 | |
| 
 | |
| Found by Coverity:
 | |
| 
 | |
|   Error: CPPCHECK_WARNING (CWE-401): [#def65] [important]
 | |
|   nbdkit-1.30.7/filters/luks/luks-encryption.c:707: error[memleak]: Memory leak: h
 | |
|   #  705|     if (memcmp (h->phdr.magic, expected_magic, LUKS_MAGIC_LEN) != 0) {
 | |
|   #  706|       nbdkit_error ("this disk does not contain a LUKS header");
 | |
|   #  707|->     return NULL;
 | |
|   #  708|     }
 | |
|   #  709|     h->phdr.version = be16toh (h->phdr.version);
 | |
| 
 | |
| Fixes: commit 468919dce6c5eb57503eacac0f67e5dd87c58e6c
 | |
| (cherry picked from commit a345cff137763f105f07bb8942c1bbefd0959cff)
 | |
| ---
 | |
|  filters/luks/luks-encryption.c | 1 +
 | |
|  1 file changed, 1 insertion(+)
 | |
| 
 | |
| diff --git a/filters/luks/luks-encryption.c b/filters/luks/luks-encryption.c
 | |
| index 06435b27..207a4e46 100644
 | |
| --- a/filters/luks/luks-encryption.c
 | |
| +++ b/filters/luks/luks-encryption.c
 | |
| @@ -710,6 +710,7 @@ load_header (nbdkit_next *next, const char *passphrase)
 | |
|  
 | |
|    if (memcmp (h->phdr.magic, expected_magic, LUKS_MAGIC_LEN) != 0) {
 | |
|      nbdkit_error ("this disk does not contain a LUKS header");
 | |
| +    free (h);
 | |
|      return NULL;
 | |
|    }
 | |
|    h->phdr.version = be16toh (h->phdr.version);
 | |
| -- 
 | |
| 2.31.1
 | |
| 
 |