summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2009-08-26 19:57:01 +0000
committerPierre Joye <pajoye@php.net>2009-08-26 19:57:01 +0000
commitbae3df750514773a04cf12ada4bdb34a7b7684f7 (patch)
treedabaea55310c99b1e65475a3d50469fcff9593c7 /TSRM
parent48d031aa6e77d7c97e232d1215d02ba086db3a12 (diff)
downloadphp-git-bae3df750514773a04cf12ada4bdb34a7b7684f7.tar.gz
- fix #44683, popen crashes when an invalid mode is passed (works on 2k8/vista/win7)
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/tsrm_win32.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index bfaac2e446..b2e94d22af 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -305,7 +305,7 @@ TSRM_API FILE *popen(const char *command, const char *type)
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
{
FILE *stream = NULL;
- int fno, str_len = strlen(type), read, mode;
+ int fno, type_len = strlen(type), read, mode;
STARTUPINFO startup;
PROCESS_INFORMATION process;
SECURITY_ATTRIBUTES security;
@@ -313,13 +313,32 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
DWORD dwCreateFlags = 0;
process_pair *proc;
char *cmd;
+ int i;
+ char *ptype = (char *)type;
TSRMLS_FETCH();
+ if (!type) {
+ return NULL;
+ }
+
+ /*The following two checks can be removed once we drop XP support */
+ type_len = strlen(type);
+ if (type_len <1 || type_len > 2) {
+ return NULL;
+ }
+
+ for (i=0; i < type_len; i++) {
+ if (!(*ptype == 'r' || *ptype == 'w' || *ptype == 'b' || *ptype == 't')) {
+ return NULL;
+ }
+ ptype++;
+ }
+
security.nLength = sizeof(SECURITY_ATTRIBUTES);
security.bInheritHandle = TRUE;
security.lpSecurityDescriptor = NULL;
- if (!str_len || !CreatePipe(&in, &out, &security, 2048L)) {
+ if (!type_len || !CreatePipe(&in, &out, &security, 2048L)) {
return NULL;
}
@@ -331,7 +350,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
startup.hStdError = GetStdHandle(STD_ERROR_HANDLE);
read = (type[0] == 'r') ? TRUE : FALSE;
- mode = ((str_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT;
+ mode = ((type_len == 2) && (type[1] == 'b')) ? O_BINARY : O_TEXT;
if (read) {
in = dupHandle(in, FALSE);