* new token to put in the actual filename (just works when debugging enabled)
authorWilfried Göesgens <willi@citadel.org>
Thu, 22 Oct 2009 18:21:35 +0000 (18:21 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 22 Oct 2009 18:21:35 +0000 (18:21 +0000)
* catch possible access to not set token parameter; off by one. usualy requester should check if the token is there in advance.
* check for presence of token in preferences before accessing it

webcit/preferences.c
webcit/subst.c

index b8330c9fdd6ac975f803661eaf77e63a1f63bffb..b7a530c5eeb974ff4e82df12cba24811d497a4e7 100644 (file)
@@ -808,9 +808,10 @@ void tmplput_CFG_Descr(StrBuf *Target, WCTemplputParams *TP)
 void tmplput_CFG_RoomValueLong(StrBuf *Target, WCTemplputParams *TP)
 {
        long lvalue;
-       long defval;
+       long defval = 0;
 
-       defval = GetTemplateTokenNumber(Target, TP, 1, 0);
+       if (TP->Tokens->nParameters > 1)
+               defval = GetTemplateTokenNumber(Target, TP, 1, 0);
        get_ROOM_PREFS_LONG(TKEY(0), &lvalue, defval);
        StrBufAppendPrintf(Target, "%ld", lvalue);
 }
index 71b8e3ff3aeabc520e2e4fed59c6bb3ff011e77f..a4a8edea2d7f601b82fa2ab94a80b925c00b39ae 100644 (file)
@@ -769,7 +769,7 @@ void GetTemplateTokenString(StrBuf *Target,
        StrBuf *Buf;
        WCTemplputParams SubTP;
 
-       if (TP->Tokens->nParameters < N) {
+       if (N >= TP->Tokens->nParameters) {
                LogTemplateError(Target, 
                                 "TokenParameter", N, TP, 
                                 "invalid token %d. this shouldn't have come till here.\n", N);
@@ -856,7 +856,7 @@ void GetTemplateTokenString(StrBuf *Target,
 long GetTemplateTokenNumber(StrBuf *Target, WCTemplputParams *TP, int N, long dflt)
 {
        long Ret;
-       if (TP->Tokens->nParameters < N) {
+       if (N >= TP->Tokens->nParameters) {
                LogTemplateError(Target, 
                                 "TokenParameter", N, TP, 
                                 "invalid token %d. this shouldn't have come till here.\n", N);
@@ -2619,6 +2619,12 @@ int ConditionalLongVector(StrBuf *Target, WCTemplputParams *TP)
        return 0;
 }
 
+
+void tmplput_CURRENT_FILE(StrBuf *Target, WCTemplputParams *TP)
+{
+       StrBufAppendTemplate(Target, TP, TP->Tokens->FileName, 0);
+}
+
 void 
 InitModule_SUBST
 (void)
@@ -2649,6 +2655,9 @@ InitModule_SUBST
        RegisterControlNS(HKEY("ITERATE:ODDEVEN"), 0, 0, tmplput_ITERATE_ODDEVEN, CTX_ITERATE);
        RegisterControlNS(HKEY("ITERATE:KEY"), 0, 0, tmplput_ITERATE_KEY, CTX_ITERATE);
        RegisterControlNS(HKEY("ITERATE:N"), 0, 0, tmplput_ITERATE_LASTN, CTX_ITERATE);
+       RegisterNamespace("CURRENTFILE", 0, 1, tmplput_CURRENT_FILE, NULL, CTX_NONE);
+
+
 }
 
 void