Skip to content

Commit 410bc37

Browse files
cosmo0920edsiper
authored andcommitted
in_forward: Handle shared_key lifetime correctly
Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent a3959d3 commit 410bc37

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

plugins/in_forward/fw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ struct flb_in_fw_config {
6060
flb_sds_t unix_perm_str; /* Permission (config map) */
6161

6262
/* secure forward */
63-
flb_sds_t shared_key; /* shared key */
63+
flb_sds_t shared_key; /* shared key */
64+
int owns_shared_key; /* own flag of shared key */
6465
flb_sds_t self_hostname; /* hostname used in certificate */
6566
struct mk_list users; /* username and password pairs */
6667
int empty_shared_key; /* use an empty string as shared key */

plugins/in_forward/fw_config.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@
2626
#include "fw_conn.h"
2727
#include "fw_config.h"
2828

29+
static void fw_destory_shared_key(struct flb_in_fw_config *config)
30+
{
31+
if (config->owns_shared_key && config->shared_key) {
32+
flb_sds_destroy(config->shared_key);
33+
}
34+
35+
config->shared_key = NULL;
36+
config->owns_shared_key = FLB_FALSE;
37+
}
38+
39+
static int fw_create_empty_shared_key(struct flb_in_fw_config *config,
40+
struct flb_input_instance *i_ins)
41+
{
42+
flb_sds_t empty_key = flb_sds_create("");
43+
if (!empty_key) {
44+
flb_plg_error(i_ins, "empty shared_key alloc failed");
45+
return -1;
46+
}
47+
else {
48+
if (config->owns_shared_key && config->shared_key) {
49+
flb_sds_destroy(config->shared_key);
50+
}
51+
config->shared_key = empty_key;
52+
config->owns_shared_key = FLB_TRUE;
53+
}
54+
55+
return 0;
56+
}
57+
2958
struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
3059
{
3160
char tmp[16];
@@ -87,10 +116,9 @@ struct flb_in_fw_config *fw_config_init(struct flb_input_instance *i_ins)
87116

88117
/* Shared Key */
89118
if (config->empty_shared_key) {
90-
if (config->shared_key) {
91-
flb_sds_destroy(config->shared_key);
119+
if (fw_create_empty_shared_key(config, i_ins) == -1) {
120+
return NULL;
92121
}
93-
config->shared_key = flb_sds_create("");
94122
}
95123

96124
/* Self Hostname */
@@ -131,7 +159,7 @@ int fw_config_destroy(struct flb_in_fw_config *config)
131159
flb_free(config->tcp_port);
132160
}
133161

134-
flb_sds_destroy(config->shared_key);
162+
fw_destory_shared_key(config);
135163
flb_sds_destroy(config->self_hostname);
136164

137165
flb_free(config);

0 commit comments

Comments
 (0)