当前位置:网站首页>Reasons for the insecurity of C language standard function scanf
Reasons for the insecurity of C language standard function scanf
2022-07-05 08:33:00 【Bright moon and clear wind - continuous improvement】
scanf It's a standard. C Standard library functions for languages ;
scanf_s Is Microsoft's , Than scanf Added a parameter , The number of characters to be input must be specified ;
eg:
char buf[5]={0};
scanf("%s",buf);// If input 1234567890, be 5 The following characters will also be read , It may be written to the location of other variables , Cause procedure
// abnormal , stay VS2019 Next test , Program crash . If input 12, It's normal
char buf[5]={0};
scanf_s("%s",buf,4);// Only the number of space characters can be stored -1 Characters Because the last space to store \0
// stay vs2019 Next test , If input ≤4 Characters , Everything is all right , If input 5 Characters or more , The program doesn't crash , however buf No data in , The reason should be 4 Within characters ( contain ) No carriage return received , So it is not written into buf in ..
边栏推荐
- Affected tree (tree DP)
- Esp8266 interrupt configuration
- 剑指 Offer 05. 替换空格
- 实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
- One question per day - replace spaces
- DCDC circuit - function of bootstrap capacitor
- 【NOI模拟赛】汁树(树形DP)
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- MATLAB小技巧(28)模糊综合评价
- Sword finger offer 09 Implementing queues with two stacks
猜你喜欢
MySQL之MHA高可用集群
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
DCDC circuit - function of bootstrap capacitor
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
FIO测试硬盘性能参数和实例详细总结(附源码)
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
Matlab tips (28) fuzzy comprehensive evaluation
Apaas platform of TOP10 abroad
猜谜语啦(9)
Circleq of linked list
随机推荐
Use indent to format code
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
关于线性稳压器的五个设计细节
99 multiplication table (C language)
Google sitemap files for rails Projects - Google sitemap files for rails projects
猜谜语啦(7)
Count the number of inputs (C language)
U8g2 drawing
Negative pressure generation of buck-boost circuit
STM32 --- serial port communication
Several important parameters of LDO circuit design and type selection
[paper reading] the latest transfer ability in deep learning: a survey in 2022
猜谜语啦(9)
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
Five design details of linear regulator
猜谜语啦(142)
QEMU STM32 vscode debugging environment configuration
Explain task scheduling based on Cortex-M3 in detail (Part 2)
MHA High available Cluster for MySQL
Let's briefly talk about the chips commonly used in mobile phones - OVP chips