summaryrefslogtreecommitdiff
blob: a8ad412a711f6af8943c105fed3fa91594d4e789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
===================================================================
RCS file: /cvsroot/mailutils/cvsroot/mailutils/mailutils/imap4d/util.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- mailutils/mailutils/imap4d/util.c	2005/01/04 17:16:42	1.62
+++ mailutils/mailutils/imap4d/util.c	2005/05/13 09:39:22	1.63
@@ -199,13 +199,14 @@
 	  {
 	    errno = 0;
 	    val = strtoul (s, &s, 10);
-	    if (val == ULONG_MAX && errno == ERANGE)
+	    if ((val == ULONG_MAX && errno == ERANGE) || val > max)
 	      {
 		if (*set)
 		  free (*set);
 		*n = 0;
 		return EINVAL;
 	      }
+	    
 	    if (low)
 	      {
 		/* Reverse it. */
@@ -400,26 +401,40 @@
 int
 util_finish (struct imap4d_command *command, int rc, const char *format, ...)
 {
-  char *tempbuf = NULL;
+  size_t size;
   char *buf = NULL;
+  char *tempbuf = NULL;
   int new_state;
   int status = 0;
   va_list ap;
-
-  asprintf (&tempbuf, "%s %s%s %s\r\n", command->tag, sc2string (rc),
-	    command->name, format);
+  char *sc = sc2string (rc);
+  
   va_start (ap, format);
-  vasprintf (&buf, tempbuf, ap);
+  vasprintf (&tempbuf, format, ap);
   va_end (ap);
+  if (!tempbuf)
+    imap4d_bye (ERR_NO_MEM);
+  
+  size = strlen (command->tag) + 1 +
+         strlen (sc) + strlen (command->name) + 1 +
+         strlen (tempbuf) + 1;
+  buf = malloc (size);
   if (!buf)
     imap4d_bye (ERR_NO_MEM);
+  strcpy (buf, command->tag);
+  strcat (buf, " ");
+  strcat (buf, sc);
+  strcat (buf, command->name);
+  strcat (buf, " ");
+  strcat (buf, tempbuf);
+  free (tempbuf);
 
   if (daemon_param.transcript)
-    syslog (LOG_DEBUG, "sent: %s", buf);
+    syslog (LOG_DEBUG, "sent: %s\r\n", buf);
 
-  status = stream_sequential_write (ostream, buf, strlen (buf));
+  stream_sequential_write (ostream, buf, strlen (buf));
   free (buf);
-  free (tempbuf);
+  stream_sequential_write (ostream, "\r\n", 2);
 
   /* Reset the state.  */
   if (rc == RESP_OK)