Interesting C-language problem

Source: Internet
Author: User

1#include <stdio.h>2 intMainvoid)3 {4     Charbuff[Ten];5memset (Buff,0,sizeof(Buff));6 gets (buff);7printf"\ n The buffer entered is [%s]\n", buff);8     return 0;9}

This is an interesting C language problem, the code run seems to be correct, but there is a security problem, the problem is the Get () function, the function is to receive a string of standard input, and do not check the size of the string buffer directly copied into the buff array, which may cause the buff memory overflow, You can use the fgets () function instead of this function in a format similar to the following:

Char *fgets (char *str,int n,file *stream);

Interesting C-language problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.