Skip to content

Commit 3254b9a

Browse files
mhusaamedsiper
authored andcommitted
in_kmsg: fix typo and use correct values for range check
* in 72d9dc8, the intention was to use strtoull, but strtoul was used, so fix that * also update the values for range check, since we are moving from int to unsigned long long * fix type mismatch with priority value Signed-off-by: Mohd Husaam Mehdi <[email protected]>
1 parent 9107895 commit 3254b9a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

plugins/in_kmsg/in_kmsg.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static inline int process_line(const char *line,
114114
struct timeval tv; /* time value */
115115
int line_len;
116116
uint64_t val;
117+
long pri_val;
117118
const char *p = line;
118119
char *end = NULL;
119120
struct flb_time ts;
@@ -123,14 +124,14 @@ static inline int process_line(const char *line,
123124
ctx->buffer_id++;
124125

125126
errno = 0;
126-
val = strtol(p, &end, 10);
127-
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
128-
|| (errno != 0 && val == 0)) {
127+
pri_val = strtol(p, &end, 10);
128+
if ((errno == ERANGE && (pri_val == INT_MAX || pri_val == INT_MIN))
129+
|| (errno != 0 && pri_val == 0)) {
129130
goto fail;
130131
}
131132

132133
/* Priority */
133-
priority = FLB_KLOG_PRI(val);
134+
priority = FLB_KLOG_PRI(pri_val);
134135

135136
if (priority > ctx->prio_level) {
136137
/* Drop line */
@@ -144,8 +145,9 @@ static inline int process_line(const char *line,
144145
}
145146
p++;
146147

147-
val = strtoul(p, &end, 10);
148-
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
148+
errno = 0;
149+
val = strtoull(p, &end, 10);
150+
if ((errno == ERANGE && val == ULLONG_MAX)
149151
|| (errno != 0 && val == 0)) {
150152
goto fail;
151153
}
@@ -154,8 +156,8 @@ static inline int process_line(const char *line,
154156
p = ++end;
155157

156158
/* Timestamp */
157-
val = strtoul(p, &end, 10);
158-
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
159+
val = strtoull(p, &end, 10);
160+
if ((errno == ERANGE && val == ULLONG_MAX)
159161
|| (errno != 0 && val == 0)) {
160162
goto fail;
161163
}

0 commit comments

Comments
 (0)