Protect precious strlens, as pointed out by John Goerzen
[citadel.git] / citadel / modules / rssclient / serv_rssclient.c
index 337ace94a765555d259a8c44b1a7f49617bb710f..17b67317fd7a5ac42c25e3e888ec954ab1acb73c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Bring external RSS feeds into rooms.
  *
- * Copyright (c) 2007-2012 by the citadel.org team
+ * Copyright (c) 2007-2015 by the citadel.org team
  *
  * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 3.
@@ -365,7 +365,7 @@ int rss_format_item(AsyncIO *IO, networker_save_message *SaveMsg)
                CM_SetField(&SaveMsg->Msg, eAuthor, HKEY("rss"));
        }
 
-       CM_SetField(&SaveMsg->Msg, eNodeName, CFG_KEY(c_nodename));
+       CM_SetField(&SaveMsg->Msg, eNodeName, CtdlGetConfigStr("c_nodename"), strlen(CtdlGetConfigStr("c_nodename")));
        if (SaveMsg->title != NULL) {
                long len;
                char *Sbj;
@@ -375,20 +375,25 @@ int rss_format_item(AsyncIO *IO, networker_save_message *SaveMsg)
                StrBufSpaceToBlank(SaveMsg->title);
                len = StrLength(SaveMsg->title);
                Sbj = html_to_ascii(ChrPtr(SaveMsg->title), len, 512, 0);
-               len = strlen(Sbj);
-               if ((len > 0) && (Sbj[len - 1] == '\n'))
-               {
-                       len --;
-                       Sbj[len] = '\0';
-               }
-               Encoded = NewStrBufPlain(Sbj, len);
-               free(Sbj);
-
-               StrBufTrim(Encoded);
-               StrBufRFC2047encode(&QPEncoded, Encoded);
+               if (!IsEmptyStr(Sbj)) {
+                       len = strlen(Sbj);
+                       if ((Sbj[len - 1] == '\n'))
+                       {
+                               len --;
+                               Sbj[len] = '\0';
+                       }
+                       Encoded = NewStrBufPlain(Sbj, len);
+               
 
-               CM_SetAsFieldSB(&SaveMsg->Msg, eMsgSubject, &QPEncoded);
-               FreeStrBuf(&Encoded);
+                       StrBufTrim(Encoded);
+                       StrBufRFC2047encode(&QPEncoded, Encoded);
+                       
+                       CM_SetAsFieldSB(&SaveMsg->Msg, eMsgSubject, &QPEncoded);
+                       FreeStrBuf(&Encoded);
+               }
+               if (Sbj != NULL) {
+                       free(Sbj);
+               }
        }
        if (SaveMsg->link == NULL)
                SaveMsg->link = NewStrBufPlain(HKEY(""));