summaryrefslogtreecommitdiff
path: root/core/kmod/0001-libkmod-file-gracefully-handle-errors-from-zlib.patch
blob: 30c92b280aedcaa6dac23e478b98d01583e8d71e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From c7d5a60d3df735a3816bbc1ff1b416a803a4f7a6 Mon Sep 17 00:00:00 2001
From: Dave Reisner <dreisner@archlinux.org>
Date: Mon, 7 May 2012 19:41:41 -0400
Subject: [PATCH 1/2] libkmod-file: gracefully handle errors from zlib

zlib won't necessarily set the system errno, and this is particularly
evident on corrupted data (which results in a double free). Use zlib's
gzerror to detect the failure, returning a generic EINVAL when zlib
doesn't provide us with an errno.
---
 libkmod/libkmod-file.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/libkmod/libkmod-file.c b/libkmod/libkmod-file.c
index 46ad8d9..8beb7e3 100644
--- a/libkmod/libkmod-file.c
+++ b/libkmod/libkmod-file.c
@@ -199,7 +199,13 @@ static int load_zlib(struct kmod_file *file)
 		if (r == 0)
 			break;
 		else if (r < 0) {
-			err = -errno;
+			int gzerr;
+			const char *gz_errmsg = gzerror(file->gzf, &gzerr);
+
+			ERR(file->ctx, "gzip: %s\n", gz_errmsg);
+
+			/* gzip might not set errno here */
+			err = gzerr == Z_ERRNO ? -errno : -EINVAL;
 			goto error;
 		}
 		did += r;
-- 
1.7.10.1