那些年掉进的坑---内存踩踏实例记录
2016-03-09 15:43
507 查看
今天遇到一下奇怪的段错误,研究发现原来是内存写越界了。
函数片段如下 ht_insert_he --> ht_index --> hashfunction
其中hashfunction实现如下
!!!把32位变量index的地址传给了hashfunction,而hashfunction把它当成了64位变量进行写入,破坏了函数栈。
函数片段如下 ht_insert_he --> ht_index --> hashfunction
void ht_insert_he(hash_table *table, hash_entry *entry) { hash_entry *tmp; unsigned int index; entry->timestamp = time(NULL); entry->next = NULL; index = ht_index(table, entry->key, entry->key_size); tmp = table->array[index]; //段错误出现位置 ...... }
unsigned int ht_index(hash_table *table, void *key, size_t key_size) { uint32_t index; //32位变量 table->hashfunction(key, key_size, global_seed, &index); index %= table->array_size; return index; }
其中hashfunction实现如下
void hashfunction(const void *key, const int len, const uint32_t seed, void *out) { const uint8_t * data = (const uint8_t*)key; const int nblocks = len / 16; ...... ((uint64_t*)out)[0] = h1; //把最后一个参数当64位进行写操作 ((uint64_t*)out)[1] = h2; }
!!!把32位变量index的地址传给了hashfunction,而hashfunction把它当成了64位变量进行写入,破坏了函数栈。
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍