]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/network/serv_network.c
Fix possible double free during sending network error messages.
[citadel.git] / citadel / modules / network / serv_network.c
index 6c9ed94b95c7625c1656f1b8814ccb8aa02383bf..95d5b51e7021f1202d06519b754f805e2bd7aeb3 100644 (file)
@@ -106,45 +106,40 @@ struct RoomProcList *rplist = NULL;
  */
 int network_usetable(struct CtdlMessage *msg)
 {
+       StrBuf *msgid;
        struct CitContext *CCC = CC;
-       char msgid[SIZ];
-       struct cdbdata *cdbut;
-       struct UseTable ut;
+       time_t now;
 
        /* Bail out if we can't generate a message ID */
-       if (msg == NULL) {
-               return(0);
-       }
-       if (msg->cm_fields['I'] == NULL) {
-               return(0);
-       }
-       if (IsEmptyStr(msg->cm_fields['I'])) {
+       if ((msg == NULL) || (msg->cm_fields['I'] == NULL) || (IsEmptyStr(msg->cm_fields['I'])))
+       {
                return(0);
        }
 
        /* Generate the message ID */
-       strcpy(msgid, msg->cm_fields['I']);
-       if (haschar(msgid, '@') == 0) {
-               strcat(msgid, "@");
+       msgid = NewStrBufPlain(msg->cm_fields['I'], -1);
+       if (haschar(ChrPtr(msgid), '@') == 0) {
+               StrBufAppendBufPlain(msgid, HKEY("@"), 0);
                if (msg->cm_fields['N'] != NULL) {
-                       strcat(msgid, msg->cm_fields['N']);
+                       StrBufAppendBufPlain(msgid, msg->cm_fields['N'], -1, 0);
                }
                else {
+                       FreeStrBuf(&msgid);
                        return(0);
                }
        }
-
-       cdbut = cdb_fetch(CDB_USETABLE, msgid, strlen(msgid));
-       if (cdbut != NULL) {
-               cdb_free(cdbut);
-               QN_syslog(LOG_DEBUG, "network_usetable() : we already have %s\n", msgid);
+       now = time(NULL);
+       if (CheckIfAlreadySeen("Networker Import",
+                              msgid,
+                              now, 0,
+                              eCheckUpdate,
+                              CCC->cs_pid, 0) != 0)
+       {
+               FreeStrBuf(&msgid);
                return(1);
        }
+       FreeStrBuf(&msgid);
 
-       /* If we got to this point, it's unique: add it. */
-       strcpy(ut.ut_msgid, msgid);
-       ut.ut_timestamp = time(NULL);
-       cdb_store(CDB_USETABLE, msgid, strlen(msgid), &ut, sizeof(struct UseTable) );
        return(0);
 }
 
@@ -393,10 +388,12 @@ void network_bounce(struct CtdlMessage *msg, char *reason)
         */
        if (msg->cm_fields['R'] == NULL) {
                free(msg->cm_fields['R']);
+               msg->cm_fields['R'] = NULL;
        }
 
        if (msg->cm_fields['D'] == NULL) {
                free(msg->cm_fields['D']);
+               msg->cm_fields['D'] = NULL;
        }
 
        snprintf(recipient, sizeof recipient, "%s@%s",