Skip to content

Commit 30b7a03

Browse files
committed
in_tail: on file_cmp, add allocation checks
Signed-off-by: Eduardo Silva <[email protected]>
1 parent bf5b38e commit 30b7a03

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

plugins/in_tail/tail_file.h

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,64 +40,57 @@
4040
#define FLB_HASH_TABLE_SIZE 50
4141
#endif
4242

43-
static inline int flb_tail_file_name_cmp(char *name,
44-
struct flb_tail_file *file)
45-
{
46-
int ret;
47-
char *a;
48-
char *b;
49-
char *a_base;
50-
char *b_base;
51-
52-
a = flb_strdup(name);
53-
b = flb_strdup(file->name);
54-
55-
a_base = flb_strdup(basename(a));
56-
b_base = basename(b);
57-
struct flb_tail_config *ctx = file->config;
58-
59-
flb_plg_info(ctx->ins, "a_base=%s b_base=%s", a_base, b_base);
60-
61-
#if defined(__linux__)
62-
ret = strcmp(name, file->name);
63-
#elif defined(FLB_SYSTEM_WINDOWS)
64-
ret = _stricmp(name, file->name);
65-
#else
66-
ret = strcmp(name, file->name);
67-
#endif
68-
69-
flb_free(a);
70-
flb_free(b);
71-
flb_free(a_base);
72-
return ret;
73-
}
74-
7543
static inline int flb_tail_target_file_name_cmp(char *name,
7644
struct flb_tail_file *file)
7745
{
7846
int ret;
7947
char *name_a = NULL;
8048
char *name_b = NULL;
81-
char *base_a;
82-
char *base_b;
49+
char *base_a = NULL;
50+
char *base_b = NULL;
8351

8452
name_a = flb_strdup(name);
53+
if (!name_a) {
54+
flb_errno();
55+
ret = -1;
56+
goto out;
57+
}
58+
8559
base_a = flb_strdup(basename(name_a));
60+
if (!base_a) {
61+
flb_errno();
62+
ret = -1;
63+
goto out;
64+
}
8665

8766
#if defined(FLB_SYSTEM_WINDOWS)
8867
name_b = flb_strdup(file->real_name);
68+
if (!name_b) {
69+
flb_errno();
70+
ret = -1;
71+
goto out;
72+
}
73+
8974
base_b = basename(name_b);
9075
ret = _stricmp(base_a, base_b);
9176
#else
9277
name_b = flb_strdup(file->real_name);
78+
if (!name_b) {
79+
flb_errno();
80+
ret = -1;
81+
goto out;
82+
}
9383
base_b = basename(name_b);
9484
ret = strcmp(base_a, base_b);
9585
#endif
9686

87+
out:
9788
flb_free(name_a);
9889
flb_free(name_b);
9990
flb_free(base_a);
10091

92+
/* FYI: 'base_b' never points to a new allocation, no flb_free is needed */
93+
10194
return ret;
10295
}
10396

0 commit comments

Comments
 (0)