我正在使用以下函数循环访问几个打开的 CDB 哈希表。有时,给定键的值与附加字符(特别是 CTRL-P(DLE 字符/0x16/0o020))一起返回。
我已经使用几个不同的实用程序检查了 cdb 键/值对,但它们都没有显示附加到值的任何附加字符。
如果我使用 cdb_read() 或 cdb_getdata() (下面的注释掉的代码),我会得到这个字符。
如果我不得不猜测,我会说我为从 cdb 函数获取结果而创建的缓冲区做错了。
非常感谢任何建议或帮助。
char* HashReducer::getValueFromDb(const string &id, vector <struct cdb *> &myHashFiles)
{
unsigned char hex_value[BUFSIZ];
size_t hex_len;
//construct a real hex (not ascii-hex) value to use for database lookups
atoh(id,hex_value,&hex_len);
char *value = NULL;
vector <struct cdb *>::iterator my_iter = myHashFiles.begin();
vector <struct cdb *>::iterator my_end = myHashFiles.end();
try
{
//while there are more databases to search and we have not found a match
for(; my_iter != my_end && !value ; my_iter++)
{
//cerr << "\n looking for this MD5:" << id << " hex(" << hex_value << ") \n";
if (cdb_find(*my_iter, hex_value, hex_len)){
//cerr << "\n\nI found the key " << id << " and it is " << cdb_datalen(*my_iter) << " long\n\n";
value = (char *)malloc(cdb_datalen(*my_iter));
cdb_read(*my_iter,value,cdb_datalen(*my_iter),cdb_datapos(*my_iter));
//value = (char *)cdb_getdata(*my_iter);
//cerr << "\n\nThe value is:" << value << " len is:" << strlen(value)<< "\n\n";
};
}
}
catch (...){}
return value;
}