Skip to content

Commit

Permalink
apr_proc_create(): Check that progname argument is quoted correctly if
Browse files Browse the repository at this point in the history
it's quoted on Windows.

git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920871 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Ivan Zhakov committed Sep 24, 2024
1 parent 16d7aaf commit eccf65f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ Changes for APR 2.0.0
*) apr_proc_create(): Fix potential handle leak when apr_proc_create() is used
from multiple threads on Windows [Ivan Zhakov]

*) apr_proc_create(): Check that progname argument is quoted correctly if
it's quoted on Windows. [Ivan Zhakov]

Changes for APR and APR-util 1.7.x and later:

*) http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/CHANGES?view=markup
Expand Down
30 changes: 30 additions & 0 deletions test/testproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,34 @@ static void test_proc_args_winbatch(abts_case* tc, void* data)
ABTS_STR_EQUAL(tc, expected, actual);
}

#ifdef WIN32
static void test_proc_unclosed_quote1(abts_case *tc, void *data)
{
apr_procattr_t *attr;
apr_status_t rv;
const char *args[] = { NULL };

rv = apr_procattr_create(&attr, p);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

rv = apr_proc_create(&newproc, "\"", args, NULL, attr, p);
ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
}

static void test_proc_unclosed_quote2(abts_case *tc, void *data)
{
apr_procattr_t *attr;
apr_status_t rv;
const char *args[] = { NULL };

rv = apr_procattr_create(&attr, p);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

rv = apr_proc_create(&newproc, "\"abc", args, NULL, attr, p);
ABTS_INT_EQUAL(tc, APR_EINVAL, rv);
}
#endif

abts_suite *testproc(abts_suite *suite)
{
suite = ADD_SUITE(suite)
Expand All @@ -311,6 +339,8 @@ abts_suite *testproc(abts_suite *suite)
abts_run_test(suite, test_proc_args, NULL);
#ifdef WIN32
abts_run_test(suite, test_proc_args_winbatch, NULL);
abts_run_test(suite, test_proc_unclosed_quote1, NULL);
abts_run_test(suite, test_proc_unclosed_quote2, NULL);
#endif

return suite;
Expand Down
11 changes: 10 additions & 1 deletion threadproc/win32/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,16 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
* XXX progname must be NULL if this is a 16 bit app running in WOW
*/
if (progname[0] == '\"') {
progname = apr_pstrmemdup(pool, progname + 1, strlen(progname) - 2);
size_t progname_len = strlen(progname);
if (progname_len < 2) {
return APR_EINVAL;
}

if (progname[progname_len - 1] != '\"') {
return APR_EINVAL;
}

progname = apr_pstrmemdup(pool, progname + 1, progname_len - 2);
}

if (attr->cmdtype == APR_PROGRAM || attr->cmdtype == APR_PROGRAM_ENV) {
Expand Down

0 comments on commit eccf65f

Please sign in to comment.