用于FUZZ测试的程序及其详解

//代码摘抄自模糊测试
[...]
    if (!(pid  = fork ()))
    {/*child*/
        ptrace(PTRACE_TRACEME,0,NULL,NULL)
            //long ptrace(enum_ptrace_request requese,pid_t_ pid, void *addr,void *data);
            //1).enum_ptrace_request 执行了ptrace要执行的命令
            //2).pid_t 进程ID
            //3).void *addr 指示了要监控的内存地址
            //4).void *data 存放读取出的或者要写入的数据
        execve(argv[0],argv,envp);//内核级系统调用,成功不返回,失败返回-1
    }
    else
    {/*parent*/
        c_pid  = pid;
    monitor:
        waitpid(pid,&status,0);//等待京城
        if(WIFEXITED(status))
        {/*程序退出信号*/
            if(!quiet)
                printf("process %d exited with code %d\n",pid,WEXITSTATUS(status));
            return(ERR_OK);
        }
        else if(WIFSIGNALED(status))
        {/*program ended because of a signal*/
            printf("process %d terminated by unhandled signal %d\n",pid,WIERMSIG(status));
            return(ERR_OK);
        }
        else if(WIFSIGNALED(status))
        //看官方介绍
        //The status field that was filled in by the wait or waitpid function
        /*The WIFSIGNALED macro is always successful.If the child process for which status was returned by the wait or waitpid function exited because it raised a signal that caused it to exit, the WIFSIGNALED macro evaluates to TRUE and the WTERMSIG macro can be used to determine which signal was raised by the child process. Otherwise, the WIFSIGNALED macro evaluates to FALSE.*/
        /*意思就是说这个函数用于响应waitpid函数,如果进行是正常的通过waitpid返回状态子进程的话,那么就为TRUE,并且wtermsig可以用于子进程引发的信号*/
        {
            if(!quiet)
                fprintf(stderr,"process %d stopped due to signal %d (%s)",pid,WSTOPSIG(status),F_signum2ascii(WSTOPSIG(status)));
                switch(WSTOPSIG(status))
                {
                    case SIGILL:
                    case SIGBUS:
                    case SIGSEGV:
                    case SIGSYS:
                        printf("program got interesting signal...\n");
                        if((ptrace(PTRACE_CONT,pid,NULL,(WSTOPSIG(status)==SIGTRAP)?0:WSTOPSIG(status)))==-1)
                        {
                            perror("ptrace");
                        }
                        ptrace(PTRACE_DETACH,pid,NULL,NULL);
                        fclose(fp);
                        return(ERR_CRASH);/*it crashed*/
                }*/deliver the signal through and keep traction*/
                if((ptrace(PTRACE_CONT,pid,NULL,(WSTOPSIG(status)==SIGTRAP)?0:WSTOPSIG(status)))==-1)
                {
                    perror("ptrace");
                }
                goto monitor;
        }
        return(ERR_OK);

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值