Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some files #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions chapter9/guard_log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* this have code injection security problem, such you input: ' && ls / && echo ' */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

char * now(){
time_t t;
time(&t);
return asctime(localtime(&t));
}

int main(){
char comment[80];
char cmd[120];
fgets(comment, 80, stdin);
sprintf(cmd, "echo '%s %s' >> reports.log", comment, now());
system(cmd);
return 0;
}
33 changes: 33 additions & 0 deletions chapter9/newshound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int main(int argc, char *argv[])
{
char *feeds[] = {"http://www.cnn.com/rss/celebs.xml",
"http://www.rolling.stone.com/rock.xml",
"http://eonline.com/gossip.xml"
};

int times = 3;
char *phrase = argv[1];
int i;
for (i = 0; i < times; i++){
char var[255];
sprintf(var, "RSS_FEED=%s", feeds[i]);
//char *vars = {var, NULL};
char *vars = {var};
pid_t pid = fork();
if(pid == -1){
fprintf(stderr,"can't fork process: %s\n", strerror(errno));
return 1;
}
if(!pid) {
if(execle("/usr/bin/python", "/usr/bin/python", "./rssgossip.py", phrase, NULL, vars) == -1)
fprintf(stderr,"can't run script: %s\n", strerror(errno));
return 1;
}
}
return 0;
}
5 changes: 5 additions & 0 deletions chapter9/system_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include<stdio.h>
int
main() {
system("ls -l");
}
3 changes: 3 additions & 0 deletions dev-tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gdb 调试器
gprof 性能分析
gcov 性能分析