aboutsummaryrefslogtreecommitdiffstats
path: root/main/net-snmp/report-empty-strings-correctly.patch
blob: b1520d9b645ef61abbaf1af5457ff89a3b5d0073 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
From d0787a2c86a80e31756965c436fac67b7d1c0f9b Mon Sep 17 00:00:00 2001
From: Bart Van Assche <bvanassche@acm.org>
Date: Fri, 11 Oct 2019 20:09:08 -0700
Subject: [PATCH] HOST-RESOURCES-MIB, UCD-SNMP-MIB: Report empty strings
 correctly

See also https://github.com/net-snmp/net-snmp/issues/26.

Fixes: 9b9c0e287b4d ("MIBs: Use asprintf() instead of snprintf() to prevent truncation")
---
 agent/mibgroup/host/hrh_filesys.c | 5 +++--
 agent/mibgroup/ucd-snmp/disk.c    | 3 ++-
 agent/mibgroup/ucd-snmp/disk_hw.c | 3 ++-
 agent/mibgroup/ucd-snmp/proc.c    | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/agent/mibgroup/host/hrh_filesys.c b/agent/mibgroup/host/hrh_filesys.c
index 354416157..073a37e98 100644
--- a/agent/mibgroup/host/hrh_filesys.c
+++ b/agent/mibgroup/host/hrh_filesys.c
@@ -219,6 +219,7 @@ var_hrhfilesys(struct variable *vp,
 {
     int             fsys_idx;
     static char    *string;
+    static char     empty_str[1];
 
     fsys_idx =
         header_hrhfilesys(vp, name, length, exact, var_len, write_method);
@@ -235,7 +236,7 @@ var_hrhfilesys(struct variable *vp,
         *var_len = 0;
         if (asprintf(&string, "%s", HRFS_entry->path) >= 0)
             *var_len = strlen(string);
-        return (u_char *) string;
+        return (u_char *)(string ? string : empty_str);
     case HRFSYS_RMOUNT:
         free(string);
         if (HRFS_entry->flags & NETSNMP_FS_FLAG_REMOTE) {
@@ -245,7 +246,7 @@ var_hrhfilesys(struct variable *vp,
             string = strdup("");
         }
         *var_len = string ? strlen(string) : 0;
-        return (u_char *) string;
+        return (u_char *)(string ? string : empty_str);
 
     case HRFSYS_TYPE:
         fsys_type_id[fsys_type_len - 1] = 
diff --git a/agent/mibgroup/ucd-snmp/disk.c b/agent/mibgroup/ucd-snmp/disk.c
index d827dcc18..52062352e 100644
--- a/agent/mibgroup/ucd-snmp/disk.c
+++ b/agent/mibgroup/ucd-snmp/disk.c
@@ -825,6 +825,7 @@ var_extensible_disk(struct variable *vp,
     struct dsk_entry entry;
     static long     long_ret;
     static char    *errmsg;
+    static char     empty_str[1];
 
 tryAgain:
     if (header_simple_table
@@ -926,7 +927,7 @@ var_extensible_disk(struct variable *vp,
                 *var_len = strlen(errmsg);
             }
         }
-        return (u_char *) (errmsg);
+        return (u_char *)(errmsg ? errmsg : empty_str);
     }
     return NULL;
 }
diff --git a/agent/mibgroup/ucd-snmp/disk_hw.c b/agent/mibgroup/ucd-snmp/disk_hw.c
index cc5da14de..e8b09a238 100644
--- a/agent/mibgroup/ucd-snmp/disk_hw.c
+++ b/agent/mibgroup/ucd-snmp/disk_hw.c
@@ -314,6 +314,7 @@ var_extensible_disk(struct variable *vp,
     unsigned long long val;
     static long     long_ret;
     static char    *errmsg;
+    static char     empty_str[1];
     netsnmp_cache  *cache;
 
     /* Update the fsys H/W module */
@@ -432,7 +433,7 @@ var_extensible_disk(struct variable *vp,
              >= 0)) {
             *var_len = strlen(errmsg);
         }
-        return (u_char *) errmsg;
+        return (u_char *)(errmsg ? errmsg : empty_str);
     }
     return NULL;
 }
diff --git a/agent/mibgroup/ucd-snmp/proc.c b/agent/mibgroup/ucd-snmp/proc.c
index 57aa2d58a..8eb5fa7ac 100644
--- a/agent/mibgroup/ucd-snmp/proc.c
+++ b/agent/mibgroup/ucd-snmp/proc.c
@@ -265,7 +265,7 @@ var_extensible_proc(struct variable *vp,
     struct myproc  *proc;
     static long     long_ret;
     static char    *errmsg;
-
+    static char     empty_str[1];
 
     if (header_simple_table
         (vp, name, length, exact, var_len, write_method, numprocs))
@@ -328,7 +328,7 @@ var_extensible_proc(struct variable *vp,
                 }
             }
             *var_len = errmsg ? strlen(errmsg) : 0;
-            return ((u_char *) errmsg);
+            return (u_char *)(errmsg ? errmsg : empty_str);
         case ERRORFIX:
             *write_method = fixProcError;
             long_return = fixproc.result;