]> git.mikk.net Git - ssm_nmsg/commitdiff
Copy HELOs into local buffer, and strip trailing \r?\ns.
authorchris mikkelson <chris@mikk.net>
Wed, 31 Mar 2010 21:27:40 +0000 (16:27 -0500)
committerchris mikkelson <chris@mikk.net>
Wed, 31 Mar 2010 21:27:40 +0000 (16:27 -0500)
ssm_nmsg.c

index 61d92169f97df36ab148a54ad3aafdfa57576c81..355956a2dc98302c7b6825c74bddfebb13c94d52 100644 (file)
@@ -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;
 }