当前位置:网站首页>记录线上bug解决list(未完待续7/4)
记录线上bug解决list(未完待续7/4)
2022-07-04 19:05:00 【谢白羽】
文章目录
一、sprintf引起的内存越界
有玩家客户端发过来的数据包解包失败,但不知道原因,所以增加了一个函数把错误的数据包以 16 进制输出到 log 的函数
char *buffer = calloc(sz*2+1, sizeof(char));
先分配一块内存,长度是要 dump 的数据长度两倍加一。然后循环
sprintf(buffer+i*2, "%02x", data[i]);
这就是我们看了几次没留意的 bug 所在:data 是 const char
类型,有符号的。当 data[i] 是一个负数时, %02x 不一定只输出 3 个字节(别忘记字符串结尾的 \0)。buffer 这块内存就被写越界了
问题
最后一个字符是负数的时候 就越界了 超过两个字符 把尾部得0覆盖掉了 所以问题就来了,解决
改成snprintf或
sprintf(buffer+i*2, "%02x", (unsigned char)data[i]);
边栏推荐
- 科普达人丨一文看懂阿里云的秘密武器“神龙架构”
- 浏览器渲染页面过程
- Template_ Judging prime_ Square root / six prime method
- Is it necessary to apply for code signing certificate for software client digital signature?
- Chrome development tool: what the hell is vmxxx file
- ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
- So this is the BGP agreement
- 2022 Health Exhibition, Beijing Health Expo, China Health Exhibition, great health exhibition November 13
- Decryption function calculates "task state and lifecycle management" of asynchronous task capability
- Jiuqi ny8b062d MCU specification /datasheet
猜你喜欢
c# . Net MVC uses Baidu ueditor rich text box to upload files (pictures, videos, etc.)
Application practice | Shuhai supply chain construction of data center based on Apache Doris
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
九齐NY8B062D MCU规格书/datasheet
原来这才是 BGP 协议
What is the application technology of neural network and Internet of things
[ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
Huawei Nova 10 series supports the application security detection function to build a strong mobile security firewall
node强缓存和协商缓存实战示例
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
随机推荐
Selected review | machine learning technology for Cataract Classification / classification
Informatics Olympiad 1336: [example 3-1] find roots and children
idea大小写快捷键
Win11U盘拒绝访问怎么办?Win11U盘拒绝访问的有效解决方法
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
Hash quiz game system development how to develop hash quiz game system development (multiple cases)
精选综述 | 用于白内障分级/分类的机器学习技术
Qt编写物联网管理平台38-多种数据库支持
Dynamic memory management
Flet教程之 07 PopupMenuButton基础入门(教程含源码)
Win11无法将值写入注册表项如何解决?
PHP pseudo original API docking method
九齐单片机NY8B062D单按键控制4种LED状态
Flet教程之 05 OutlinedButton基础入门(教程含源码)
idea插件
Chrome development tool: what the hell is vmxxx file
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
Small hair cat Internet of things platform construction and application model
Win11亮度被锁定怎么办?Win11亮度被锁定的解决方法
word中使用自动插入题注功能