Skip to content

Commit 3d708fb

Browse files
nokute78edsiper
authored andcommitted
time: add strict event time type checking
Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent bbd84fb commit 3d708fb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/flb_time.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ int flb_time_append_to_msgpack(struct flb_time *tm, msgpack_packer *pk, int fmt)
247247
return ret;
248248
}
249249

250+
static inline int is_eventtime(msgpack_object *obj)
251+
{
252+
if (obj->via.ext.type != 0 || obj->via.ext.size != 8) {
253+
return FLB_FALSE;
254+
}
255+
return FLB_TRUE;
256+
}
257+
250258
int flb_time_msgpack_to_time(struct flb_time *time, msgpack_object *obj)
251259
{
252260
uint32_t tmp;
@@ -261,6 +269,11 @@ int flb_time_msgpack_to_time(struct flb_time *time, msgpack_object *obj)
261269
time->tm.tv_nsec = ((obj->via.f64 - time->tm.tv_sec) * ONESEC_IN_NSEC);
262270
break;
263271
case MSGPACK_OBJECT_EXT:
272+
if (is_eventtime(obj) != FLB_TRUE) {
273+
flb_warn("[time] unknown ext type. type=%d size=%d",
274+
obj->via.ext.type, obj->via.ext.size);
275+
return -1;
276+
}
264277
memcpy(&tmp, &obj->via.ext.ptr[0], 4);
265278
time->tm.tv_sec = (uint32_t) ntohl(tmp);
266279
memcpy(&tmp, &obj->via.ext.ptr[4], 4);

0 commit comments

Comments
 (0)