Skip to content

Commit 72d9dc8

Browse files
mhusaamedsiper
authored andcommitted
in_kmsg: use strtoull to fix timestamp parsing on 32-bit systems
On 32-bit systems, kmsg stops producing logs after sometime. This is because of ERANGE error. The ERANGE error occurs when processing timestamp, because although val is of type uint64_t, strtol cannot process the value because of long being only 4 bytes, which is not sufficient to hold the timestamp values. It would be better to use strtoull instead, to make sure we have 8 bytes to store the value on all systems. Signed-off-by: Mohd Husaam Mehdi <[email protected]>
1 parent 9cbada2 commit 72d9dc8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

plugins/in_kmsg/in_kmsg.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <sys/stat.h>
3737
#include <sys/time.h>
3838
#include <inttypes.h>
39+
#include <time.h>
3940

4041
#include "in_kmsg.h"
4142

@@ -143,7 +144,7 @@ static inline int process_line(const char *line,
143144
}
144145
p++;
145146

146-
val = strtol(p, &end, 10);
147+
val = strtoul(p, &end, 10);
147148
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
148149
|| (errno != 0 && val == 0)) {
149150
goto fail;
@@ -153,7 +154,7 @@ static inline int process_line(const char *line,
153154
p = ++end;
154155

155156
/* Timestamp */
156-
val = strtol(p, &end, 10);
157+
val = strtoul(p, &end, 10);
157158
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
158159
|| (errno != 0 && val == 0)) {
159160
goto fail;

0 commit comments

Comments
 (0)