当前位置: 首页>>代码示例>>C++>>正文


C++ POPEN函数代码示例

本文整理汇总了C++中POPEN函数的典型用法代码示例。如果您正苦于以下问题:C++ POPEN函数的具体用法?C++ POPEN怎么用?C++ POPEN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了POPEN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: run_test

bool run_test(const std::string& path, const std::string& test, bool& warnings_occured, const std::string& cmd = "")
{
	FILE* bin;
#ifdef PE_BLISS_WINDOWS
		bin = POPEN(("\"\"" + path + test + "\" \"" + path + cmd + "\"\" 2>&1" + DEV_NULL).c_str(), "r");
#else
		bin = POPEN(("\"" + path + test + "\" \"" + path + cmd + "\" 2>&1" + DEV_NULL).c_str(), "r");
#endif

	if(bin == NULL)
	{
		std::cerr << "Cannot execute testsuite" << std::endl;
		return false;
	}

	char buf[256];
	while(fgets(buf, sizeof(buf), bin) != NULL)
	{
		warnings_occured = true;
		std::cerr << buf;
	}

#ifdef PE_BLISS_WINDOWS
	return PCLOSE(bin) == 0;
#else
	int stat;
	int wstat = WEXITSTATUS(stat = PCLOSE(bin));
	if(stat < 0 || (wstat != 0 && wstat != 128 + SIGPIPE))
		return false;
	else
		return true;
#endif
}
开发者ID:BackupGGCode,项目名称:portable-executable-library,代码行数:33,代码来源:main.cpp

示例2: goodG2B1

/* goodG2B1() - use goodsource and badsink by changing the GLOBAL_CONST_TRUE to GLOBAL_CONST_FALSE */
static void goodG2B1()
{
    char * data;
    char dataBuffer[100] = "";
    data = dataBuffer;
    if(GLOBAL_CONST_FALSE)
    {
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
    }
    else
    {
        /* FIX: full path is specified */
        strcpy(data, GOOD_OS_COMMAND);
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Executing the popen() function without specifying the full path to the executable
         * can allow an attacker to run their own program */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:27,代码来源:CWE426_Untrusted_Search_Path__char_popen_09.c

示例3: goodG2B1

/* goodG2B1() - use goodsource and badsink by changing the switch to switch(5) */
static void goodG2B1()
{
    wchar_t * data;
    wchar_t data_buf[100] = FULL_COMMAND;
    data = data_buf;
    switch(5)
    {
    case 6:
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
        break;
    default:
        /* FIX: Append a fixed string to data (not user / external input) */
        wcscat(data, L"*.*");
        break;
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, L"wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:27,代码来源:CWE78_OS_Command_Injection__wchar_t_file_popen_15.c

示例4: goodG2B

/* goodG2B() - use goodsource and badsink by changing the "if" so that
 * both branches use the GoodSource */
static void goodG2B()
{
    char * data;
    char dataBuffer[100] = "";
    data = dataBuffer;
    if(globalReturnsTrueOrFalse())
    {
        /* FIX: full path is specified */
        strcpy(data, GOOD_OS_COMMAND);
    }
    else
    {
        /* FIX: full path is specified */
        strcpy(data, GOOD_OS_COMMAND);
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Executing the popen() function without specifying the full path to the executable
         * can allow an attacker to run their own program */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:28,代码来源:CWE426_Untrusted_Search_Path__char_popen_12.c

示例5: goodG2B1

/* goodG2B1() - use goodsource and badsink by changing the 5==5 to 5!=5 */
static void goodG2B1()
{
    char * data;
    char data_buf[100] = FULL_COMMAND;
    data = data_buf;
    if(5!=5)
    {
        /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */
        printLine("Benign, fixed string");
    }
    else
    {
        /* FIX: Append a fixed string to data (not user / external input) */
        strcat(data, "*.*");
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:26,代码来源:CWE78_OS_Command_Injection__char_environment_popen_03.c

示例6: goodG2B

/* goodG2B() - use goodsource and badsink by changing the "if" so that
 * both branches use the GoodSource */
static void goodG2B()
{
    char * data;
    char data_buf[100] = FULL_COMMAND;
    data = data_buf;
    if(globalReturnsTrueOrFalse())
    {
        /* FIX: Append a fixed string to data (not user / external input) */
        strcat(data, "*.*");
    }
    else
    {
        /* FIX: Append a fixed string to data (not user / external input) */
        strcat(data, "*.*");
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:27,代码来源:CWE78_OS_Command_Injection__char_console_popen_12.c

示例7: CWE78_OS_Command_Injection__char_environment_popen_16_bad

void CWE78_OS_Command_Injection__char_environment_popen_16_bad()
{
    char * data;
    char data_buf[100] = FULL_COMMAND;
    data = data_buf;
    while(1)
    {
        {
            /* Append input from an environment variable to data */
            size_t dataLen = strlen(data);
            char * environment = GETENV(ENV_VARIABLE);
            /* If there is data in the environment variable */
            if (environment != NULL)
            {
                /* POTENTIAL FLAW: Read data from an environment variable */
                strncat(data+dataLen, environment, 100-dataLen-1);
            }
        }
        break;
    }
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:30,代码来源:CWE78_OS_Command_Injection__char_environment_popen_16.c

示例8: goodG2B

/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2B()
{
    char * data;
    char * *dataPtr1 = &data;
    char * *dataPtr2 = &data;
    char data_buf[100] = FULL_COMMAND;
    data = data_buf;
    {
        char * data = *dataPtr1;
        /* FIX: Append a fixed string to data (not user / external input) */
        strcat(data, "*.*");
        *dataPtr1 = data;
    }
    {
        char * data = *dataPtr2;
        {
            FILE *pipe;
            /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
            pipe = POPEN(data, "wb");
            if (pipe != NULL)
            {
                PCLOSE(pipe);
            }
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:27,代码来源:CWE78_OS_Command_Injection__char_listen_socket_popen_32.c

示例9: mu_rndwn_sem_all

int mu_rndwn_sem_all(void)
{
	int 			save_errno, exit_status = SS_NORMAL, semid;
	char			entry[MAX_ENTRY_LEN];
	FILE			*pf;
	char			fname[MAX_FN_LEN + 1], *fgets_res;
	boolean_t 		rem_sem;
	shm_parms		*parm_buff;

	if (NULL == (pf = POPEN(IPCS_SEM_CMD_STR ,"r")))
        {
		save_errno = errno;
		gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(8) ERR_SYSCALL, 5, RTS_ERROR_LITERAL("POPEN()"), CALLFROM, save_errno);
                return ERR_MUNOTALLSEC;
        }
	while (NULL != (FGETS(entry, SIZEOF(entry), pf, fgets_res)) && entry[0] != '\n')
	{
		if (-1 != (semid = parse_sem_id(entry)))
		{
			if (is_orphaned_gtm_semaphore(semid))
			{	/* semval == 0 and corresponding shared memory has been removed */
				if (-1 != semctl(semid, 0, IPC_RMID))
				{
					gtm_putmsg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_SEMREMOVED, 1, semid);
					send_msg_csa(CSA_ARG(NULL) VARLSTCNT(3) ERR_SEMREMOVED, 1, semid);
				}
			}
		}
	}
	pclose(pf);
	return exit_status;
}
开发者ID:mihawk,项目名称:fis-gtm,代码行数:32,代码来源:mu_rndwn_all.c

示例10: Gnuplot

	explicit Gnuplot(const std::string cmd = "gnuplot") : 
					 boost::iostreams::stream<boost::iostreams::file_descriptor_sink>(
					 FILENO(pout = POPEN(cmd.c_str(), "w")),
					 boost::iostreams::never_close_handle),
					 pout(pout), // keeps '-Weff++' quiet
					 gp_pty(NULL),
					 debug_messages(false)
	{
		*this << std::scientific << std::setprecision(18);  // refer <iomanip>
	}
开发者ID:osandov,项目名称:tetrak-cpp,代码行数:10,代码来源:Gnuplot.hpp

示例11: CWE78_OS_Command_Injection__wchar_t_listen_socket_popen_54e_badSink

void CWE78_OS_Command_Injection__wchar_t_listen_socket_popen_54e_badSink(wchar_t * data)
{
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, L"wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:12,代码来源:CWE78_OS_Command_Injection__wchar_t_listen_socket_popen_54e.c

示例12: CWE78_OS_Command_Injection__wchar_t_environment_popen_65b_goodG2BSink

/* goodG2B uses the GoodSource with the BadSink */
void CWE78_OS_Command_Injection__wchar_t_environment_popen_65b_goodG2BSink(wchar_t * data)
{
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, L"wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:13,代码来源:CWE78_OS_Command_Injection__wchar_t_environment_popen_65b.c

示例13: POPEN

CWE78_OS_Command_Injection__wchar_t_connect_socket_popen_84_bad::~CWE78_OS_Command_Injection__wchar_t_connect_socket_popen_84_bad()
{
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, L"wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:12,代码来源:CWE78_OS_Command_Injection__wchar_t_connect_socket_popen_84_bad.cpp

示例14: CWE78_OS_Command_Injection__char_file_popen_65b_badSink

void CWE78_OS_Command_Injection__char_file_popen_65b_badSink(char * data)
{
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, "wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:12,代码来源:CWE78_OS_Command_Injection__char_file_popen_65b.c

示例15: goodG2BSink

/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2BSink(wchar_t * data)
{
    {
        FILE *pipe;
        /* POTENTIAL FLAW: Execute command in data possibly leading to command injection */
        pipe = POPEN(data, L"wb");
        if (pipe != NULL)
        {
            PCLOSE(pipe);
        }
    }
}
开发者ID:maurer,项目名称:tiamat,代码行数:13,代码来源:CWE78_OS_Command_Injection__wchar_t_file_popen_44.c


注:本文中的POPEN函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。