From 1bd05a26bada57f79784fd0d1bd91c8db7476da3 Mon Sep 17 00:00:00 2001 From: chris mikkelson Date: Wed, 31 Mar 2010 16:27:40 -0500 Subject: [PATCH] Copy HELOs into local buffer, and strip trailing \r?\ns. --- ssm_nmsg.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/ssm_nmsg.c b/ssm_nmsg.c index 61d9216..355956a 100644 --- a/ssm_nmsg.c +++ b/ssm_nmsg.c @@ -144,18 +144,26 @@ ssm_nmsg_connect(struct conn *c) return SSM_PASS; } +#define HELOMAX 1024 static int ssm_nmsg_helo(struct conn *c, const char *cmd, int len, int argoff) { struct ssm_nmsg_state *nms = ssm_getpriv(&ss_module, c); - uint8_t *data = malloc(len + 1); + char buf[HELOMAX]; + const char *s; + char *t, *end; + + if (len - argoff > HELOMAX - 1) return SSM_PASS; + + for (s = cmd + argoff, end = t = buf; s < cmd + len; s++) { + *t++ = *s; + if (*s != '\r' && *s != '\n') end = t; + } + *end = 0; - memcpy(data,cmd,len); - data[len] = 0; if (nms && nms->msg) - nmsg_message_set_field(nms->msg, "helo", 0, data+argoff, - len - argoff + 1); - free(data); + nmsg_message_set_field(nms->msg, "helo", 0, (uint8_t *)buf, + end - buf + 1); return SSM_PASS; } -- 2.50.1