C Process and system calls

Source: Internet
Author: User
Tags sprintf

This blog explains the process and system call related knowledge

There is such a scene, I need to enter a string of text, and then the text I entered with a local timestamp saved in a file, can be initially understood as a memo line

1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 5 /**6 * Get a current time7  */8 Char*Now () {9 time_t t;TenTime (&t); One     returnAsctime (LocalTime (&t)); A } -  - intMainintargcConst Char*argv[]) { the      -     Charcomment[ the]; -     Charcmd[ -]; -      +Fgets (Comment, the, stdin); -     //sprintf Write the contents into a variable +sprintf (CMD,"Echo '%s%s ' >> Reports.log", Comment,now ()); A     //call the system's method to execute this command at system (CMD); -     return 0; -}

The result of running the program is to generate a file

But sometimes the systemt () function is unsafe.

" echo ' && ls/&& echo '%s ' >> reports.log ", Now ());

Modify the upper code, and you'll get the result.

Lists the contents of the root directory, so you can use the command to delete files or start viruses

C Process and system calls

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.