* don't ignore the last char of a template
authorWilfried Göesgens <willi@citadel.org>
Sat, 13 Dec 2008 14:04:51 +0000 (14:04 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 13 Dec 2008 14:04:51 +0000 (14:04 +0000)
* don't access aray indexes before chcking them.

webcit/subst.c
webcit/webserver.c

index 716a46e718077bbb15a6419d7d10262d593611f8..41aad9274daad0bb6e6d3818cf6795c8f1956215 100644 (file)
@@ -936,21 +936,21 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
        case SV_CUST_STR_CONDITIONAL:
        case SV_CONDITIONAL:
        case SV_NEG_CONDITIONAL:
-               if (NewToken->Params[1]->lvalue == 0) {
+               if (NewToken->nParameters <2) {
                        lprintf(1, "Conditional (in '%s' line %ld); "
-                               "Conditional ID mustn't be 0! [%s]\n", 
+                               "require at least 2 parameters, you gave %ld params [%s]\n", 
                                ChrPtr(pTmpl->FileName),
                                NewToken->Line,
+                               NewToken->nParameters, 
                                ChrPtr(NewToken->FlatToken));
                        NewToken->Flags = 0;
                        break;
                }
-               if (NewToken->nParameters <2) {
+               if (NewToken->Params[1]->lvalue == 0) {
                        lprintf(1, "Conditional (in '%s' line %ld); "
-                               "require at least 2 parameters, you gave %ld params [%s]\n", 
+                               "Conditional ID mustn't be 0! [%s]\n", 
                                ChrPtr(pTmpl->FileName),
                                NewToken->Line,
-                               NewToken->nParameters, 
                                ChrPtr(NewToken->FlatToken));
                        NewToken->Flags = 0;
                        break;
@@ -1070,7 +1070,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere)
                pts = pch;
 
                /** Found one? parse it. */
-               for (; pch < pE - 1; pch ++) {
+               for (; pch <= pE - 1; pch ++) {
                        if (*pch == '"')
                                InDoubleQuotes = ! InDoubleQuotes;
                        else if (*pch == '\'')
@@ -1081,7 +1081,7 @@ void *load_template(StrBuf *filename, StrBuf *Key, HashList *PutThere)
                                break;
                        }
                }
-               if (pch + 1 >= pE)
+               if (pch + 1 > pE)
                        continue;
                pte = pch;
                PutNewToken(NewTemplate, 
index 5c107f3821094480ffe957903b40804e030eacf7..480cdcf0d4dde6639f2eba37037ad16083c6a332 100644 (file)
@@ -699,6 +699,16 @@ int main(int argc, char **argv)
        SortHash = NewHash(1, NULL);
 
        LoadZoneFiles();
+       StrBuf *foo=NewStrBufPlain("", -1);
+       StrBuf *bar = NewStrBufPlain("A", -1);
+
+       StrBufExtract_token(bar, foo, 0, '|');
+       StrBufExtract_token(bar, foo, 1, '|');
+       StrBufExtract_token(bar, foo, 2, '|');
+       StrBufExtract_token(bar, foo, 3, '|');
+       StrBufExtract_token(bar, foo, 4, '|');
+       StrBufExtract_token(bar, foo, 5, '|');
+       StrBufExtract_token(bar, foo, 6, '|');
 
 #ifdef DBG_PRINNT_HOOKS_AT_START
        dbg_PrintHash(HandlerHash, nix, NULL);