if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 6 Apr 2011 22:46:34 +0000 (00:46 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 17:50:17 +0000 (17:50 +0000)
17 files changed:
webcit/auth.c
webcit/blogview_renderer.c
webcit/groupdav_propfind.c
webcit/inetconf.c
webcit/mainmenu.c
webcit/messages.c
webcit/preferences.c
webcit/pushemail.c
webcit/roomlist.c
webcit/roomops.c
webcit/serv_func.c
webcit/siteconfig.c
webcit/tcp_sockets.c
webcit/useredit.c
webcit/webcit.c
webcit/who.c
webcit/wiki.c

index ebf7aa14cdeb4be1bdf834a510520ff9b1fedfeb..35c2063b3f2e14a22bb97d46d0df3a9c480956ce 100644 (file)
@@ -303,6 +303,7 @@ void finalize_openid_login(void)
                                long HKLen;
                                const char *HKey;
                                HashPos *Cursor;
+                               int len;
                                
                                Cursor = GetNewHashPos (WCC->Hdr->urlstrings, 0);
                                while (GetNextHashPos(WCC->Hdr->urlstrings, Cursor, &HKLen, &HKey, &U)) {
@@ -315,7 +316,9 @@ void finalize_openid_login(void)
                                serv_puts("000");
 
                                linecount = 0;
-                               while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) 
+                               while (len = StrBuf_ServGetln(Buf), 
+                                      ((len >= 0) &&
+                                       ((len != 3) || strcmp(ChrPtr(Buf), "000") )))
                                {
                                        if (linecount == 0) result = NewStrBufDup(Buf);
                                        if (!strcasecmp(ChrPtr(result), "authenticate")) {
index 9a93a686cad02040d30600c70a8299acef35d649..215fa94ef222726e6228493cf314ab78b67b37ea 100644 (file)
@@ -122,13 +122,17 @@ struct bltr blogview_learn_thread_references(long msgnum)
 {
        StrBuf *Buf;
        StrBuf *r;
+       int len;
        struct bltr bltr = { 0, 0 } ;
        Buf = NewStrBuf();
        r = NewStrBuf();
        serv_printf("MSG0 %ld|1", msgnum);              /* top level citadel headers only */
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
-               while (StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (len = StrBuf_ServGetln(Buf), 
+                      ((len >= 0) && 
+                       ((len != 3) || strcmp(ChrPtr(Buf), "000") )))
+               {
                        if (!strncasecmp(ChrPtr(Buf), "msgn=", 5)) {
                                StrBufCutLeft(Buf, 5);
                                bltr.id = HashLittle(ChrPtr(Buf), StrLength(Buf));
index 01dbe4f6177300562c5df06edf80a793525937d3..f644bb740a834d3dd9759a55ac4f85d1fb3bd9c1 100644 (file)
@@ -680,7 +680,10 @@ void groupdav_propfind(void)
 
        StrBuf_ServGetln(MsgNum);
        if (GetServerStatus(MsgNum, NULL) == 1)
-               while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000"))  {
+               while (BufLen = StrBuf_ServGetln(MsgNum), 
+                      ((BufLen >= 0) && 
+                       ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000"))  ))
+               {
                        msgs = realloc(msgs, ++num_msgs * sizeof(long));
                        msgs[num_msgs-1] = StrTol(MsgNum);
                }
@@ -692,7 +695,9 @@ void groupdav_propfind(void)
                serv_printf("MSG0 %ld|3", msgs[i]);
                StrBuf_ServGetln(MsgNum);
                if (GetServerStatus(MsgNum, NULL) == 1)
-                       while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) 
+                       while (BufLen = StrBuf_ServGetln(MsgNum), 
+                              ((BufLen >= 0) && 
+                               ((BufLen != 3) || strcmp(ChrPtr(MsgNum), "000")) ))
                        {
                                if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) {
                                        strcpy(uid, &ChrPtr(MsgNum)[5]);
index ab284758766ce0be1a5a244ac64447209347856b..a370634bcdd6174e61cef5df2dd35989dd6c5f9d 100644 (file)
@@ -62,7 +62,10 @@ void load_inetconf(void)
        if (GetServerStatus(Buf, NULL) == 1) {
                CfgToken = NewStrBuf();
                while ((len = StrBuf_ServGetln(Buf),
-                       strcmp(ChrPtr(Buf), "000"))) {
+                       ((len >= 0) && 
+                        ((len != 3) ||
+                         strcmp(ChrPtr(Buf), "000")))))
+               {
                        Value = NewStrBuf();
  
                        StrBufExtract_token(CfgToken, Buf, 1, '|');
index 8ddc28aa21d51e102eb9d4cf506fc50954abb65e..8942e93905b0e2b1758d3393070385dbb5701348 100644 (file)
@@ -58,7 +58,8 @@ void do_generic(void)
                LineBuf = NewStrBuf();
                StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
                while (!Done) {
-                       StrBuf_ServGetln(LineBuf);
+                       if (StrBuf_ServGetln(LineBuf) < 0)
+                               break;
                        if ( (StrLength(LineBuf)==3) && 
                             !strcmp(ChrPtr(LineBuf), "000")) {
                                Done = 1;
index d099de86d4ee09f8c7f572e826eafa4838f2f925..231d98eef54d9c3a4d8479fab8f310618d2994a1 100644 (file)
@@ -537,8 +537,10 @@ message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSu
        Msg = (message_summary*)malloc(sizeof(message_summary));
        memset(Msg, 0, sizeof(message_summary));
        while (len = StrBuf_ServGetln(Buf),
+              (len >= 0) && 
               ((len != 3)  ||
-               strcmp(ChrPtr(Buf), "000")== 0)){
+               strcmp(ChrPtr(Buf), "000")))
+       {
                buf = ChrPtr(Buf);
                ebuf = strchr(ChrPtr(Buf), '=');
                nBuf = ebuf - buf;
@@ -589,7 +591,10 @@ int load_msg_ptrs(const char *servcmd,
                return (Stat->nummsgs);
        }
        Buf2 = NewStrBuf();
-       while (len = StrBuf_ServGetln(Buf), ((len != 3) || strcmp(ChrPtr(Buf), "000")!= 0))
+       while (len = StrBuf_ServGetln(Buf), 
+              ((len >= 0) &&
+               ((len != 3) || 
+                strcmp(ChrPtr(Buf), "000")!= 0)))
        {
                if (Stat->nummsgs < Stat->maxload) {
                        skipit = 0;
index a492f5d06c6a837cf963637ead91edd75029994c..02b9102b5872c9b4a8ef7baa21b016f4fbc57150 100644 (file)
@@ -154,7 +154,8 @@ void ParsePref(HashList **List, StrBuf *ReadBuf)
        Preference *LastData = NULL;
                                
        while (!Done) {
-               StrBuf_ServGetln(ReadBuf);
+               if (StrBuf_ServGetln(ReadBuf) < 0)
+                       break;
                if ( (StrLength(ReadBuf)==3) && 
                     !strcmp(ChrPtr(ReadBuf), "000")) {
                        Done = 1;
@@ -221,7 +222,7 @@ void load_preferences(void)
                serv_puts("000");
        }
        while (!Done &&
-              StrBuf_ServGetln(ReadBuf)) {
+              (StrBuf_ServGetln(ReadBuf) >= 0)) {
                if ( (StrLength(ReadBuf)==3) && 
                     !strcmp(ChrPtr(ReadBuf), "000")) {
                        Done = 1;
@@ -234,7 +235,7 @@ void load_preferences(void)
                serv_printf("MSG0 %ld", msgnum);
                StrBuf_ServGetln(ReadBuf);
                if (GetServerStatus(ReadBuf, NULL) == 1) {
-                       while (StrBuf_ServGetln(ReadBuf),
+                       while ((StrBuf_ServGetln(ReadBuf) >= 0) && 
                               (strcmp(ChrPtr(ReadBuf), "text") && 
                                strcmp(ChrPtr(ReadBuf), "000"))) {
                        }
@@ -375,7 +376,7 @@ void save_preferences(void)
                serv_puts("000");
        }
        while (!Done &&
-              StrBuf_ServGetln(ReadBuf)) {
+              (StrBuf_ServGetln(ReadBuf) >= 0)) {
                if ( (StrLength(ReadBuf)==3) && 
                     !strcmp(ChrPtr(ReadBuf), "000")) {
                        Done = 1;
index 82ee5682ac63c8985024e260405eb00c797669ce..6fdf455cdc665498d918d02c8f3a36254ebcb0a5 100644 (file)
@@ -29,7 +29,7 @@ void display_pushemail(void)
                        serv_puts("subj|__ Push email settings __");
                        serv_puts("000");
                        while (!Done &&
-                              StrBuf_ServGetln(Buf)) {
+                              StrBuf_ServGetln(Buf) >= 0) {
                                if ( (StrLength(Buf)==3) && 
                                     !strcmp(ChrPtr(Buf), "000")) {
                                        Done = 1;
@@ -45,7 +45,7 @@ void display_pushemail(void)
                        int i =0;
                        Done = 0;
                        while (!Done &&
-                              StrBuf_ServGetln(Buf)) {
+                              StrBuf_ServGetln(Buf) >= 0) {
                                if (( (StrLength(Buf)==3) && 
                                      !strcmp(ChrPtr(Buf), "000"))||
                                    ((StrLength(Buf)==4) && 
@@ -58,7 +58,7 @@ void display_pushemail(void)
                        if (!strcmp(ChrPtr(Buf), "text")) {
                                Done = 0;
                                while (!Done &&
-                                      StrBuf_ServGetln(Buf)) {
+                                      StrBuf_ServGetln(Buf) >= 0) {
                                        if ( (StrLength(Buf)==3) && 
                                             !strcmp(ChrPtr(Buf), "000")) {
                                                Done = 1;
@@ -125,7 +125,7 @@ void save_pushemail(void)
        }
 
        while (!Done &&
-              StrBuf_ServGetln(Buf)) {
+              StrBuf_ServGetln(Buf) >= 0) {
                if ( (StrLength(Buf)==3) && 
                     !strcmp(ChrPtr(Buf), "000")) {
                        Done = 1;
index bb59c953d974211e6109bce7f0597da9f109d4fd..c86a7f78dcf104cfec004830d9a80c8977432943 100644 (file)
@@ -21,7 +21,7 @@ HashList *GetWhoKnowsHash(StrBuf *Target, WCTemplputParams *TP)
        if (GetServerStatus(Line, &State) == 1) 
        {
                Whok = NewHash(1, Flathash);
-               while(!Done && StrBuf_ServGetln(Line))
+               while(!Done && (StrBuf_ServGetln(Line) >= 0) )
                        if ( (StrLength(Line)==3) && 
                             !strcmp(ChrPtr(Line), "000")) 
                        {
@@ -108,7 +108,7 @@ HashList *GetFloorListHash(StrBuf *Target, WCTemplputParams *TP)
        StrBufTCP_read_line(Buf, &WC->serv_sock, 0, &Err); /* '100', we hope */
        if (GetServerStatus(Buf, NULL) == 1) 
        {
-               while(!Done && StrBuf_ServGetln(Buf))
+               while(!Done && StrBuf_ServGetln(Buf) >= 0)
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) 
                        {
@@ -230,7 +230,7 @@ HashList *GetRoomListHash(StrBuf *Target, WCTemplputParams *TP)
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) 
        {
-               while(!Done && StrBuf_ServGetln(Buf))
+               while(!Done && (StrBuf_ServGetln(Buf) >= 0))
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) 
                        {
@@ -341,7 +341,7 @@ HashList *GetNetConfigHash(StrBuf *Target, WCTemplputParams *TP)
                const char *Pos = NULL;
                int Done = 0;
 
-               while(!Done && StrBuf_ServGetln(Line))
+               while(!Done && (StrBuf_ServGetln(Line) >= 0))
                        if ( (StrLength(Line)==3) && 
                             !strcmp(ChrPtr(Line), "000"))
                        {
index 5c076b0c9c1a7e4969f0e95f7eda2c11f41cb4cf..2052066dc9eaf837e4b9f3cbb8df7dbe8c529ce7 100644 (file)
@@ -854,7 +854,8 @@ void do_invt_kick(void)
                        if ((StrLength(User) > 0) && (Kick))
                        {
                                serv_printf("KICK %s", ChrPtr(User));
-                               StrBuf_ServGetln(Buf);
+                               if (StrBuf_ServGetln(Buf) < 0)
+                                       break;
                                if (GetServerStatus(Buf, NULL) != 2) {
                                        StrBufCutLeft(Buf, 4);
                                        AppendImportantMessage(SKEY(Buf));
@@ -870,7 +871,8 @@ void do_invt_kick(void)
                        else if ((StrLength(User) > 0) && (Invite))
                        {
                                serv_printf("INVT %s", ChrPtr(User));
-                               StrBuf_ServGetln(Buf);
+                               if (StrBuf_ServGetln(Buf) < 0)
+                                       break;
                                if (GetServerStatus(Buf, NULL) != 2) {
                                        StrBufCutLeft(Buf, 4);
                                        AppendImportantMessage(SKEY(Buf));
index 6e9b3001c1c16117fb1214bd39c1f19b05a5cb98..0c89245516b225e459433d0ba970a0ef5863067a 100644 (file)
@@ -50,6 +50,7 @@ ServInfo *get_serv_info(StrBuf *browser_host, StrBuf *user_agent)
        ServInfo *info;
        StrBuf *Buf;
        int a;
+       int rc;
 
        Buf = NewStrBuf();
 
@@ -96,7 +97,11 @@ ServInfo *get_serv_info(StrBuf *browser_host, StrBuf *user_agent)
        info = (ServInfo*)malloc(sizeof(ServInfo));
        memset(info, 0, sizeof(ServInfo));
        a = 0;
-       while (StrBuf_ServGetln(Buf), (strcmp(ChrPtr(Buf), "000")!= 0)) {
+       while (rc = StrBuf_ServGetln(Buf),
+              (rc >= 0) &&
+              ((rc != 3) || 
+               strcmp(ChrPtr(Buf), "000")))
+       {
                switch (a) {
                case 0:
                        info->serv_pid = StrToi(Buf);
index f0e8b4937080c4e7258438b5c97cf5f9bb1d07f1..f893b4833e9437fa037ab3e337a5304ec2035e49 100644 (file)
@@ -231,9 +231,9 @@ void load_siteconfig(void)
        }
        i = 0;
        while (len = StrBuf_ServGetln(Buf),
+              (len >= 0) && 
               (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) &&
-              ((len != 3) || (strcmp(ChrPtr(Buf), "000")!= 0))
-               )
+              ((len != 3) || strcmp(ChrPtr(Buf), "000")))
        {
                Put(Cfg,
                    ServerConfig[i].Key, 
index b7ab06ba7cdf9a6ef0edddac5ea40d2a93e1c9a2..f03e003016df5b1fe935d3f07a0c8ff014a65b8a 100644 (file)
@@ -404,7 +404,10 @@ int serv_read_binary(StrBuf *Ret, size_t total_len, StrBuf *Buf)
                }
 
                serv_printf("READ %d|%d", bytes_read, total_len-bytes_read);
-               if ( (StrBuf_ServGetln(Buf) > 0) && (GetServerStatus(Buf, NULL) == 6) ) {
+               if ( (rc = StrBuf_ServGetln(Buf) > 0) && (GetServerStatus(Buf, NULL) == 6) ) 
+               {
+                       if (rc < 0)
+                               return rc;
                        StrBufCutLeft(Buf, 4);
                        this_block = StrTol(Buf);
                        rc = StrBuf_ServGetBLOBBuffered(Ret, this_block);
index 51db279ea9f90f3fef122afb11c6bf1b555ec578..c76188b4e1e0930bcb39fc44bd46b4040f14583b 100644 (file)
@@ -269,8 +269,10 @@ HashList *iterate_load_userlist(StrBuf *Target, WCTemplputParams *TP)
 
                while (!Done) {
                        len = StrBuf_ServGetln(Buf);
-                       if ((len == 3) &&
-                           (strcmp(ChrPtr(Buf), "000")==0)) {
+                       if ((len <0) || 
+                           ((len == 3) &&
+                            strcmp(ChrPtr(Buf), "000")))
+                       {
                                Done = 1;
                                break;
                        }
index 20b4896d2ac2e3150b8dc428b8faf9346b60eb04..e1e270c2ffbc5386274825662ecb09fe4ff66f01 100644 (file)
@@ -424,7 +424,8 @@ void ajax_servcmd(void)
                }
        case 1:
                while (!Done) {
-                       StrBuf_ServGetln(Buf);
+                       if (StrBuf_ServGetln(Buf) < 0)
+                               break;
                        if ( (StrLength(Buf)==3) && 
                             !strcmp(ChrPtr(Buf), "000")) {
                                Done = 1;
index c3df2556dfef80c3fa6824165d09b788c5112531..9fdd9a90b53838f47377cde67ad00a520bee23eb 100644 (file)
@@ -48,7 +48,10 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf)
        serv_puts("RWHO");
        StrBuf_ServGetln(Buf);
        if (GetServerStatus(Buf, NULL) == 1) {
-               while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while (BufLen = StrBuf_ServGetln(Buf), 
+                      ((BufLen >= 0) && 
+                       ((BufLen != 3) || strcmp(ChrPtr(Buf), "000"))))
+               {
                        if (BufLen <= 0)
                            continue;
                        Pos = NULL;
index 452fc82ec4df569a2c3b0012492567729a4a8fc4..b183fdbd42d24d043272c1fc06bef858d6658c99 100644 (file)
@@ -181,7 +181,7 @@ void tmplput_display_wiki_history(StrBuf *Target, WCTemplputParams *TP)
                wc_printf("<th>%s</th>", _("Date"));
                wc_printf("<th>%s</th>", _("Author"));
 
-               while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while((StrBuf_ServGetln(Buf) >= 0) &&  strcmp(ChrPtr(Buf), "000")) {
 
                        rev_date = extract_long(ChrPtr(Buf), 1);
                        webcit_fmt_date(rev_date_displayed, sizeof rev_date_displayed, rev_date, DATEFMT_FULL);
@@ -299,7 +299,7 @@ void tmplput_display_wiki_pagelist(StrBuf *Target, WCTemplputParams *TP)
                wc_printf("<table class=\"wiki_pagelist_background\">");
                wc_printf("<th>%s</th>", _("Page title"));
 
-               while(StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
+               while((StrBuf_ServGetln(Buf) >= 0) && strcmp(ChrPtr(Buf), "000")) {
                        StrBufExtract_token(pagetitle, Buf, 1, '|');
 
                        if (!bmstrcasestr((char *)ChrPtr(pagetitle), "_HISTORY_")) {    /* no history pages */