Blame SOURCES/100-fix-double-free-hasher.patch

cf1a29
--- libkcapi-1.2.0/apps/kcapi-hasher.c.fix-double-free-hasher	2020-05-26 16:31:28.296332614 +0200
cf1a29
+++ libkcapi-1.2.0/apps/kcapi-hasher.c	2020-05-26 16:37:07.681011437 +0200
cf1a29
@@ -301,7 +301,7 @@ static int hasher(struct kcapi_handle *h
cf1a29
 				fprintf(stderr,
cf1a29
 					"Use of mmap failed mapping %zu bytes at offset %" PRId64 " of file %s (%d)\n",
cf1a29
 					mapped, (int64_t)offset, filename, ret);
cf1a29
-				goto out;
cf1a29
+				return ret;
cf1a29
 			}
cf1a29
 			/* Compute hash */
cf1a29
 			memblock_p = memblock;
cf1a29
@@ -311,8 +311,10 @@ static int hasher(struct kcapi_handle *h
cf1a29
 						 INT_MAX : (uint32_t)left;
cf1a29
 
cf1a29
 				ret = kcapi_md_update(handle, memblock_p, todo);
cf1a29
-				if (ret < 0)
cf1a29
-					goto out;
cf1a29
+				if (ret < 0) {
cf1a29
+			        munmap(memblock, mapped);
cf1a29
+					return ret;
cf1a29
+                }
cf1a29
 				left -= todo;
cf1a29
 				memblock_p += todo;
cf1a29
 			} while (left);
cf1a29
@@ -329,7 +331,7 @@ static int hasher(struct kcapi_handle *h
cf1a29
 
cf1a29
 			ret = kcapi_md_update(handle, tmpbuf, bufsize);
cf1a29
 			if (ret < 0)
cf1a29
-				goto out;
cf1a29
+				return ret;
cf1a29
 		}
cf1a29
 		kcapi_memset_secure(tmpbuf, 0, sizeof(tmpbuf));
cf1a29
 	}
cf1a29
@@ -340,7 +342,7 @@ static int hasher(struct kcapi_handle *h
cf1a29
 		if (hashlen > (uint32_t)ret) {
cf1a29
 			fprintf(stderr, "Invalid truncated hash size: %lu > %i\n",
cf1a29
 			        (unsigned long)hashlen, ret);
cf1a29
-			goto out;
cf1a29
+			return ret;
cf1a29
 		}
cf1a29
 
cf1a29
 		if (!hashlen)
cf1a29
@@ -376,11 +378,6 @@ static int hasher(struct kcapi_handle *h
cf1a29
 		fprintf(stderr, "Generation of hash for file %s failed (%d)\n",
cf1a29
 			filename ? filename : "stdin", ret);
cf1a29
 	}
cf1a29
-
cf1a29
-out:
cf1a29
-	if (memblock)
cf1a29
-		munmap(memblock, mapped);
cf1a29
-
cf1a29
 	return ret;
cf1a29
 }
cf1a29