* Fixed a potential memory leak in enumeration of MIME parts
authorArt Cancro <ajc@citadel.org>
Thu, 1 May 2003 15:33:05 +0000 (15:33 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 1 May 2003 15:33:05 +0000 (15:33 +0000)
webcit/ChangeLog
webcit/messages.c

index db530d66494861633f387e73cb67e14849e032c6..047ae669a171e1bfc54fadb2cb784f08faeabb9e 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 410.17  2003/05/01 15:33:05  ajc
+* Fixed a potential memory leak in enumeration of MIME parts
+
 Revision 410.16  2003/05/01 03:11:35  ajc
 * When static content is requested, fetch it without trying to connect
   to Citadel first.
@@ -1352,3 +1355,4 @@ Sun Dec  6 19:50:55 EST 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 049bc9a3ebbd22f0bc56b87e4b88ad6a921dc334..4bd8b0940e6ebc4f43f4d73f9bb24469694a5464 100644 (file)
@@ -205,7 +205,7 @@ void read_message(long msgnum) {
        char mime_content_type[SIZ];
        char mime_disposition[SIZ];
        int mime_length;
-       char *mime_http = NULL;
+       char mime_http[SIZ];
        char m_subject[SIZ];
        char from[SIZ];
        char node[SIZ];
@@ -225,6 +225,7 @@ void read_message(long msgnum) {
        strcpy(reply_to, "");
        strcpy(vcard_partnum, "");
        strcpy(cal_partnum, "");
+       strcpy(mime_http, "");
 
        serv_printf("MSG4 %ld", msgnum);
        serv_gets(buf);
@@ -299,15 +300,8 @@ void read_message(long msgnum) {
                        mime_length = extract_int(&buf[5], 5);
 
                        if (!strcasecmp(mime_disposition, "attachment")) {
-                               if (mime_http == NULL) {
-                                       mime_http = malloc(512);
-                                       strcpy(mime_http, "");
-                               }
-                               else {
-                                       mime_http = realloc(mime_http,
-                                               strlen(mime_http) + 512);
-                               }
-                               sprintf(&mime_http[strlen(mime_http)],
+                               snprintf(&mime_http[strlen(mime_http)],
+                                       (sizeof(mime_http) - strlen(mime_http) - 1),
                                        "<A HREF=\"/output_mimepart?"
                                        "msgnum=%ld&partnum=%s\" "
                                        "TARGET=\"wc.%ld.%s\">"
@@ -322,15 +316,8 @@ void read_message(long msgnum) {
 
                        if ((!strcasecmp(mime_disposition, "inline"))
                           && (!strncasecmp(mime_content_type, "image/", 6)) ){
-                               if (mime_http == NULL) {
-                                       mime_http = malloc(512);
-                                       strcpy(mime_http, "");
-                               }
-                               else {
-                                       mime_http = realloc(mime_http,
-                                               strlen(mime_http) + 512);
-                               }
-                               sprintf(&mime_http[strlen(mime_http)],
+                               snprintf(&mime_http[strlen(mime_http)],
+                                       (sizeof(mime_http) - strlen(mime_http) - 1),
                                        "<IMG SRC=\"/output_mimepart?"
                                        "msgnum=%ld&partnum=%s\">",
                                        msgnum, mime_partnum);
@@ -471,9 +458,8 @@ void read_message(long msgnum) {
 
 
        /* Afterwards, offer links to download attachments 'n' such */
-       if (mime_http != NULL) {
+       if (strlen(mime_http) > 0) {
                wprintf("%s", mime_http);
-               free(mime_http);
        }
 
        /* Handler for vCard parts */