if StrBuf_ServGetln() is called in a loop, its return value has to be checked for...
authorWilfried Goesgens <dothebart@citadel.org>
Thu, 7 Apr 2011 21:41:53 +0000 (23:41 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Thu, 7 Apr 2011 21:41:53 +0000 (23:41 +0200)
15 files changed:
webcit/auth.c
webcit/groupdav_propfind.c
webcit/inetconf.c
webcit/mainmenu.c
webcit/messages.c
webcit/preferences.c
webcit/pushemail.c
webcit/roomlist.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 99e11606d04b875fce63a4102db21d74e7d2e68a..d37382f224d8a22c144114e7a5a19a6dff3e35dd 100644 (file)
@@ -384,6 +384,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)) {
@@ -396,7 +397,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 867cec9ee03f697a617fc88be3372e9ad23253d2..08dd90ad28377867fc10605df5d1b79df2c1c3a2 100644 (file)
@@ -682,7 +682,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);
                }
@@ -694,7 +697,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 269967e4a7f9c243d7184c66fcd6885633f76a3c..9e9a73e7737f1442229eef93c38baa003388a15c 100644 (file)
@@ -69,7 +69,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 52aa826fc0ada6a668141ead117c31fb79654a53..5022a0c0318a89cddde7ea0333f13da4ae463e6f 100644 (file)
@@ -114,9 +114,10 @@ void do_generic(void)
                }
        case 1:
                while (!Done) {
-                       StrBuf_ServGetln(Buf);
-                       if ( (StrLength(Buf)==3) && 
-                            !strcmp(ChrPtr(Buf), "000")) {
+                       if (StrBuf_ServGetln(LineBuf) < 0)
+                               break;
+                       if ( (StrLength(LineBuf)==3) && 
+                            !strcmp(ChrPtr(LineBuf), "000")) {
                                Done = 1;
                        }
                        StrEscAppend(WCC->WBuf, Buf, NULL, 0, 0);
index ebe8f61ddacf9c6be8c20436e316d113ea497184..b20186ba0646c72fc4ac6af1935a43919dbe8219 100644 (file)
@@ -547,8 +547,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;
@@ -599,7 +601,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 379fa6509dec76ee80bd5aaa28faff8f42088389..1007811725f85efe9399b90edcd2cae801c3a1bd 100644 (file)
@@ -157,7 +157,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;
@@ -224,7 +225,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;
@@ -237,7 +238,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"))) {
                        }
@@ -378,7 +379,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 482ee8a58afa60095f81f8ca50be31f24eef45e1..2f59929eb72037a921ba346be619356feb46adfc 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;
@@ -126,7 +126,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 928e34adc440e346e1304205d1b5476503e61fc2..078ba6c2ab8c1ae4571def72f4b53322202f42eb 100644 (file)
@@ -64,7 +64,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")) 
                        {
@@ -181,7 +181,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")) 
                        {
index 50bf1f771d993d5f306d67fd9ece24090d53562e..f4162a5a0e84ed87dc8ec71bc5bca0d537e84092 100644 (file)
@@ -54,6 +54,7 @@ ServInfo *get_serv_info(StrBuf *browser_host, StrBuf *user_agent)
        ServInfo *info;
        StrBuf *Buf;
        int a;
+       int rc;
 
        Buf = NewStrBuf();
 
@@ -100,7 +101,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 6a5eea83ba186cf3550e4b70b485c0c6527baa84..4b1fc5ce0a4ad1c8e3990b993f370b505402f3f4 100644 (file)
@@ -225,10 +225,10 @@ void load_siteconfig(void)
        serv_getln(buf, sizeof buf);
        i = 0;
        Buf = NewStrBuf();
-       while ((sizeof(ServerConfig) / sizeof(CfgMapping)) &&
-              (len = StrBuf_ServGetln(Buf),
-               strcmp(ChrPtr(Buf), "000")) && 
-              (i <= sizeof(ServerConfig))) 
+       while (len = StrBuf_ServGetln(Buf),
+              (len >= 0) && 
+              (i <= (sizeof(ServerConfig) / sizeof(CfgMapping))) &&
+              ((len != 3) || strcmp(ChrPtr(Buf), "000")))
        {
                Put(Cfg,
                    ServerConfig[i].Key, 
index e783feb7fca0ca5f9643b581a92bee5d1ad0c381..6bbef24fb5fb7459fb001af957229c48bb3a6757 100644 (file)
@@ -333,7 +333,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 85e55f43a988491d94886e2bc5b757d2703358a2..a95670a8024da8946eddcdae3a167a26c176be67 100644 (file)
@@ -272,8 +272,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 251c7df9a74422f98d62295a6e5d4269c8cc7228..9de1ad242289209df0864d5fbb24f95e3ce8c0fb 100644 (file)
@@ -407,7 +407,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 692481e382dfec128f8850925dc73c0776dc9e27..8904325878763a5c5073e5a1431da1f83601b992 100644 (file)
@@ -51,7 +51,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 2b0ba7f888eb905a6d5e19a63e8a7f928d86748b..627424fe5d9547be112043e51370b9f5ce1c078f 100644 (file)
@@ -169,7 +169,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);
@@ -290,7 +290,7 @@ void tmplput_display_wiki_pagelist(StrBuf *Target, WCTemplputParams *TP)
 
                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 */