diff options
author | Jeremy Sowden <jeremy@azazel.net> | 2021-11-30 10:55:35 +0000 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2021-11-30 20:55:17 +0100 |
commit | ae3d0f59e2d1962d2a8f97dfb3e05b32ca11ea82 (patch) | |
tree | 718068595e681e0aced7fb6182ea8b054e4e600c | |
parent | 721aa6f74f17f56dd82873aefffb2d6683918b79 (diff) |
filter: PWSNIFF: replace malloc+strncpy with strndup
There are a couple of instances of allocating memory with `malloc`,
followed by copying a string to it with `strncpy` and adding an explicit
assignment of `\0` to terminate the string. Replace them with
`strndup`.
Add an enum to name indices of output keys.
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | filter/ulogd_filter_PWSNIFF.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/filter/ulogd_filter_PWSNIFF.c b/filter/ulogd_filter_PWSNIFF.c index 934ff0e..ef9e021 100644 --- a/filter/ulogd_filter_PWSNIFF.c +++ b/filter/ulogd_filter_PWSNIFF.c @@ -35,10 +35,14 @@ #define DEBUGP(format, args...) #endif - #define PORT_POP3 110 #define PORT_FTP 21 +enum pwsniff_output_keys { + PWSNIFF_OUT_KEY_USER, + PWSNIFF_OUT_KEY_PASS, +}; + static uint16_t pwsniff_ports[] = { PORT_POP3, PORT_FTP, @@ -116,21 +120,17 @@ static int interp_pwsniff(struct ulogd_pluginstance *pi) if (len) { char *ptr; - ptr = (char *) malloc(len+1); + ptr = strndup((char *)begp, len); if (!ptr) return ULOGD_IRET_ERR; - strncpy(ptr, (char *)begp, len); - ptr[len] = '\0'; - okey_set_ptr(&ret[0], ptr); + okey_set_ptr(&ret[PWSNIFF_OUT_KEY_USER], ptr); } if (pw_len) { char *ptr; - ptr = (char *) malloc(pw_len+1); + ptr = strndup((char *)pw_begp, pw_len); if (!ptr) return ULOGD_IRET_ERR; - strncpy(ptr, (char *)pw_begp, pw_len); - ptr[pw_len] = '\0'; - okey_set_ptr(&ret[1], ptr); + okey_set_ptr(&ret[PWSNIFF_OUT_KEY_PASS], ptr); } return ULOGD_IRET_OK; } |