aboutsummaryrefslogtreecommitdiffstats
path: root/main/nagios-plugins/check_mysql_query-fix-use-after-free.patch
blob: 0f9a2784a581d773ece2de51f0f05260bc88b6d0 (plain) (blame)
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
From: simon-alpine@fraho.eu
Subject: mysql_check_query crashes on alpine 3.13 after accessing free'd data
Upstream: reported

see https://gitlab.alpinelinux.org/alpine/aports/-/issues/12601
and https://github.com/nagios-plugins/nagios-plugins/issues/602

--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -143,17 +143,17 @@
 		die (STATE_CRITICAL, "QUERY %s: Fetch row error - %s\n", _("CRITICAL"), error);
 	}
 
-	/* free the result */
-	mysql_free_result (res);
-
-	/* close the connection */
-	mysql_close (&mysql);
-
 	if (! is_numeric(row[0])) {
 		die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]);
 	}
 
 	value = strtod(row[0], NULL);
+
+	/* free the result */
+	mysql_free_result (res);
+
+	/* close the connection */
+	mysql_close (&mysql);
 
 	if (verbose >= 3)
 		printf("mysql result: %f\n", value);