当前位置:网站首页>记录线上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]);
边栏推荐
- Introduction to ACM combination counting
- 华为云云商店首页 Banner 资源位申请
- 更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
- SSRS筛选器的IN运算(即包含于)用法
- Every time I look at the interface documents of my colleagues, I get confused and have a lot of problems...
- 2022 version of stronger jsonpath compatibility and performance test (snack3, fastjson2, jayway.jsonpath)
- Write it down once Net analysis of thread burst height of an industrial control data acquisition platform
- 一文搞懂Go语言中文件的读写与创建
- [ismb2022 tutorial] the picture shows the precision medicine of learning. Marinka zitnik, Harvard University, keynote speaker, with 87 ppt
- QT writing the Internet of things management platform 38- multiple database support
猜你喜欢
NLP、视觉、芯片...AI重点方向发展几何?青源会展望报告发布[附下载]
Aiming at the "amnesia" of deep learning, scientists proposed that based on similarity weighted interleaved learning, they can board PNAS
Win11共享文件打不开怎么办?Win11共享文件打不开的解决方法
Neural network IOT platform construction (IOT platform construction practical tutorial)
C language - Introduction - Foundation - grammar - process control (VII)
一文搞懂Go语言中文件的读写与创建
Selected review | machine learning technology for Cataract Classification / classification
QT writing the Internet of things management platform 38- multiple database support
Practice examples to understand JS strong cache negotiation cache
NLP, vision, chip What is the development direction of AI? Release of the outlook report of Qingyuan Association [download attached]
随机推荐
Integritee通过XCM集成至Moonriver,为其生态系统带来企业级隐私解决方案
Optimize if code with policy mode [policy mode]
AP8022开关电源小家电ACDC芯片离线式开关电源IC
LeetCode 871. 最低加油次数
Introduction to ACM combination counting
Flet教程之 04 FilledTonalButton基础入门(教程含源码)
So this is the BGP agreement
Six stones programming: about code, there are six triumphs
In operation (i.e. included in) usage of SSRs filter
Flet教程之 07 PopupMenuButton基础入门(教程含源码)
Related concepts of federal learning and motivation (1)
什么是区块哈希竞猜游戏系统开发?哈希竞猜游戏系统开发(案例成熟)
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Informatics Olympiad 1336: [example 3-1] find roots and children
长城证券开户安全吗 股票开户流程网上开户
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
Stack: how to realize the judgment of valid brackets?
Regular replacement [JS, regular expression]
Free soldier