#include "chiark_tcl_cdb.h"
+#define KEYLEN_MAX (INT_MAX/2)
+
#define ftello ftell
#define fseeko fseek
#define MAX_SUFFIX 5
static void pathbuf_init(Pathbuf *pb, const char *pathb) {
- int l= strlen(pathb);
+ size_t l= strlen(pathb);
+ assert(l < INT_MAX);
pb->buf= TALLOC(l + MAX_SUFFIX + 1);
memcpy(pb->buf, pathb, l);
pb->sfx= pb->buf + l;
*p= 0;
errno=0; ul= strtoul(numbuf, &ep, 10);
- if (*ep || errno || ul >= INT_MAX/2) return -2;
+ if (*ep || errno || ul >= KEYLEN_MAX) return -2;
*num_r= ul;
return 0;
}
static int writerecord(FILE *f, const char *key, const HashValue *val) {
int r;
- r= fprintf(f, "+%d,%d:%s->", strlen(key), val->len, key);
+ r= fprintf(f, "+%d,%d:%s->", (int)strlen(key), val->len, key);
if (r<0) return -1;
r= fwrite(val->data, 1, val->len, f);
HashValue *val;
int rc, r;
+ if (strlen(key) >= KEYLEN_MAX)
+ return cht_staticerr(ip, "key too long", "CDB KEYOVERFLOW");
+
if (!rw->logfile) return cht_staticerr
(ip, "previous compact failed; cdbwr must be closed and reopened "
"before any further updates", "CDB BROKEN");
return cht_cdb_donesomelookup(ip, rw_v, def, result, data, dlen,
cht_cdb_storeanswer_hb);
}
-
-int cht_do_cdbtoplevel_cdb_wr(ClientData cd, Tcl_Interp *ip,
- const Cdbwr_SubCommand* subcmd,
- int objc, Tcl_Obj *const *objv) {
- return subcmd->func((void*)subcmd,ip,objc,objv);
-}