diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-21 16:59:30 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-02-22 10:50:56 +0100 |
commit | 914c1ec1d4e65ac599762388df5a22696e2f968b (patch) | |
tree | 868efb1f7bef97318c7da07f390d4ce9cb5ad9e6 /TSRM | |
parent | 427ebce6295b296c1f18f6bd927bf3cd295be815 (diff) | |
download | php-git-914c1ec1d4e65ac599762388df5a22696e2f968b.tar.gz |
Stricter validation for popen mode argument on Windows
Context: The ext/standard/tests/file/popen_pclose_error-win32.phpt
test often fails under parallel testing, because the "is not recognized
as an internal or external command" message doesn't actually have a
guaranteed position in the output.
While looking into this, I noticed that this test on Windows tests
something very different (invalid comand) than on Linux (invalid mode).
Here I'm adjusting the Windows popen implementation so it immediately
fails on a `rw` mode, just like it does on Linux.
Diffstat (limited to 'TSRM')
-rw-r--r-- | TSRM/tsrm_win32.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c index 704d30e209..131523c253 100644 --- a/TSRM/tsrm_win32.c +++ b/TSRM/tsrm_win32.c @@ -468,17 +468,17 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, return NULL; } - /*The following two checks can be removed once we drop XP support */ type_len = (int)strlen(type); - if (type_len <1 || type_len > 2) { + 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++; + if (ptype[0] != 'r' && ptype[0] != 'w') { + return NULL; + } + + if (type_len > 1 && (ptype[1] != 'b' && ptype[1] != 't')) { + return NULL; } cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c ")+2); |