Case-insensitive tokens
Julien ÉLIE
julien at trigofacile.com
Fri Aug 5 23:47:29 UTC 2011
Hi,
Using "ctlinnd addhist" currently gives weird results:
% ctlinnd addhist '<pouet>' 1312575175 1312575175 1312575175 ''
Ok
% grephistory -e '<pouet>'
@95A9ADC6403A29596359BECC38B651C17020@
% ctlinnd addhist '<pouet2>' 1312575175 1312575175 1312575175 '@aaaaaaaaaaaaaaaaaaaaa@'
Ok
% grephistory -e '<pouet2>'
@CACACACACACACACACACAA9BA95191402003F@
% ctlinnd addhist '<pouet3>' 1312575175 1312575175 1312575175 '@a'
Ok
% grephistory -e '<pouet3>'
@CAA95191C66E8A89FC1B8B495EFE9EE9301E@
It looks like memory is not initialized.
I suggest the following patch:
* checking that the last argument to "ctlinnd addhist"
is either '' or a valid token;
* using @000000000000000000000000000000000000@ when the token
is empty ('') for "ctlinnd addhist" or badly formatted for
any other function calling TextToToken();
* fixing the result of the hexadecimal conversion when a lowercase
character is used. Transform it to an uppercase character.
I hope it will not break things. The test suite is still OK after
these changes.
Should we go on accepting case-insensitive tokens (transforming
them into uppercase chars), or should we reject lowercase hex values?
As it is not the same value ('a' != 'A'), it gives different results
in our conversion routines. That's why maybe it would be wiser to
reject lowercase tokens.
Index: innd/cc.c
===================================================================
--- innd/cc.c (révision 9281)
+++ innd/cc.c (copie de travail)
@@ -259,6 +259,9 @@
return "1 Bad posted date";
Data.Posted = atol(av[3]);
+ /* Allow empty tokens, but not badly formatted tokens. */
+ if (*av[4] != '\0' && !IsToken(av[4]))
+ return "1 Bad token";
token = TextToToken(av[4]);
if (Mode == OMrunning)
ok = InndHisWrite(msgid, Data.Arrived, Data.Posted,
Index: storage/interface.c
===================================================================
--- storage/interface.c (révision 9281)
+++ storage/interface.c (copie de travail)
@@ -90,12 +90,12 @@
** Converts a hex digit and converts it to a int
*/
static int hextodec(const int c) {
- return isdigit((unsigned char) c) ? (c - '0') : ((c - 'A') + 10);
+ return isdigit((unsigned char) c) ? (c - '0') : ((toupper(c) - 'A') + 10);
}
/*
** Converts a textual representation of a token back to a native
-** representation
+** representation.
*/
TOKEN TextToToken(const char *text) {
const char *p;
@@ -103,14 +103,18 @@
int i;
TOKEN token;
- if (text[0] == '@')
- p = &text[1];
- else
- p = text;
+ /* Return an empty token (with only '0' chars) if the text is
+ * not a valid token. */
+ if (!IsToken(text)) {
+ memset(&token, 0, sizeof(TOKEN));
+ } else {
+ /* First char is a '@'. */
+ p = &text[1];
- for (q = (char *)&token, i = 0; i != sizeof(TOKEN); i++) {
- q[i] = (hextodec(*p) << 4) + hextodec(*(p + 1));
- p += 2;
+ for (q = (char *)&token, i = 0; i != sizeof(TOKEN); i++) {
+ q[i] = (hextodec(*p) << 4) + hextodec(*(p + 1));
+ p += 2;
+ }
}
return token;
}
--
Julien ÉLIE
« En France, on n'a pas de pétrole, mais on a des idées ! Alors,
j'ai troqué ma deux-chevaux contre une deux-bœufs ! » (Raymond
Devos)
More information about the inn-workers
mailing list