当前位置:网站首页>记录线上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]);
边栏推荐
- Practice examples to understand JS strong cache negotiation cache
- The problem of the maximum difference between the left and right maxima
- 泰山OFFICE技术讲座:关于背景(底纹和高亮)的顺序问题
- What are the consequences of closing the read / write channel?
- 【深度学习】一文看尽Pytorch之十九种损失函数
- Lingyun going to sea | Wenhua online & Huawei cloud: creating a new solution for smart teaching in Africa
- repeat_ P1002 [NOIP2002 popularization group] cross the river pawn_ dp
- Length of the longest integrable subarray
- In operation (i.e. included in) usage of SSRs filter
- NetCore3.1 Json web token 中间件
猜你喜欢

Ziguang zhanrui completed the first 5g R17 IOT NTN satellite on the Internet of things in the world

Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法

C # better operation mongodb database

Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company

电脑怎么保存网页到桌面上使用

Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing

QT writing the Internet of things management platform 38- multiple database support

Actual combat simulation │ JWT login authentication

Detailed explanation of Audi EDI invoice message

Application practice | Shuhai supply chain construction of data center based on Apache Doris
随机推荐
Win11怎么搜索无线显示器?Win11查找无线显示器设备的方法
Hash哈希竞猜游戏系统开发如何开发丨哈希竞猜游戏系统开发(多套案例)
In the first month of its launch, the tourist praise rate of this campsite was as high as 99.9%! How did he do it?
Qt五子棋人机对战画棋子之QPainter的使用误区总结
repeat_ P1002 [NOIP2002 popularization group] cross the river pawn_ dp
长城证券开户安全吗 股票开户流程网上开户
C language - Introduction - Foundation - grammar - process control (VII)
Oracle database, numbers Force 2 decimal places to display-Alibaba Cloud
C server log module
MySQL中的日期时间类型与格式化方式
Template_ Large integer subtraction_ Regardless of size
[Beijing Xunwei] i.mx6ull development board porting Debian file system
Flet教程之 08 AppBar工具栏基础入门(教程含源码)
针对深度学习的“失忆症”,科学家提出基于相似性加权交错学习,登上PNAS
Offset function and windowing function
Informatics Olympiad 1336: [example 3-1] find roots and children
Taishan Office Technology Lecture: about the order of background (shading and highlighting)
Regular replacement [JS, regular expression]
Detailed explanation of Audi EDI invoice message
Is it safe for Great Wall Securities to open an account? Stock account opening process online account opening