* re-designed loop with strlen inside
authorWilfried Göesgens <willi@citadel.org>
Wed, 20 Feb 2008 22:19:44 +0000 (22:19 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 20 Feb 2008 22:19:44 +0000 (22:19 +0000)
* if validate_recipients hits bonus-blanks, ignore them.
* use snprintf even if we are shure our buffer is big enough.

citadel/modules/calendar/serv_calendar.c
citadel/msgbase.c

index cc3f58c810819bc792325c5ccdfda9eaaa82ee41..4d0144ba2dfa71a6f4052f7bc12d9d5d04aec351 100644 (file)
@@ -1680,6 +1680,7 @@ void ical_send_out_invitations(icalcomponent *cal) {
        icalproperty *attendee = NULL;
        char summary_string[SIZ];
        icalproperty *summary = NULL;
+       size_t reqsize;
 
        if (cal == NULL) {
                lprintf(CTDL_ERR, "ERROR: trying to reply to NULL event?\n");
@@ -1778,9 +1779,10 @@ void ical_send_out_invitations(icalcomponent *cal) {
        icalcomponent_free(encaps);     /* Don't need this anymore. */
        if (serialized_request == NULL) return;
 
-       request_message_text = malloc(strlen(serialized_request) + SIZ);
+       reqsize = strlen(serialized_request) + SIZ;
+       request_message_text = malloc(reqsize);
        if (request_message_text != NULL) {
-               sprintf(request_message_text,
+               snprintf(request_message_text, reqsize,
                        "Content-type: text/calendar\r\n\r\n%s\r\n",
                        serialized_request
                );
index 75f8d436618f8b71a687b8f5b430f65ed8d425a6..dc4032160768cf304e9797811e4dbd5ca1414750 100644 (file)
@@ -2473,15 +2473,18 @@ long CtdlSubmitMsg(struct CtdlMessage *msg,     /* message to save */
                strcpy(content_type, "text/plain");
                mptr = bmstrcasestr(msg->cm_fields['M'], "Content-type:");
                if (mptr != NULL) {
+                       char *aptr;
                        safestrncpy(content_type, &mptr[13], sizeof content_type);
                        striplt(content_type);
-                       for (a = 0; a < strlen(content_type); ++a) {
-                               if ((content_type[a] == ';')
-                                   || (content_type[a] == ' ')
-                                   || (content_type[a] == 13)
-                                   || (content_type[a] == 10)) {
-                                       content_type[a] = 0;
+                       aptr = content_type;
+                       while (!IsEmptyStr(aptr)) {
+                               if ((*aptr == ';')
+                                   || (*aptr == ' ')
+                                   || (*aptr == 13)
+                                   || (*aptr == 10)) {
+                                       *aptr = 0;
                                }
+                               else aptr++;
                        }
                }
        }
@@ -3282,6 +3285,8 @@ struct recptypes *validate_recipients(char *supplied_recipients,
                }
 
                striplt(this_recp);
+               if (IsEmptyStr(this_recp))
+                       break;
                lprintf(CTDL_DEBUG, "Evaluating recipient #%d: %s\n", num_recps, this_recp);
                ++num_recps;
                mailtype = alias(this_recp);