Skip to content

Commit 7076612

Browse files
committed
Add integer overflow check to ap_escape_shell_cmd()
ap_escape_shell_cmd at line 1820 computes 2 * strlen(str) + 1 without checking for overflow. Same pattern as the URL escape functions fixed in the previous commit. Add (APR_SIZE_MAX - 1) / 2 guard, consistent with ap_escape_html2's overflow protection.
1 parent 53f4fbb commit 7076612

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

server/util.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,8 +1816,12 @@ AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *str)
18161816
char *cmd;
18171817
unsigned char *d;
18181818
const unsigned char *s;
1819+
apr_size_t len = strlen(str);
18191820

1820-
cmd = apr_palloc(p, 2 * strlen(str) + 1); /* Be safe */
1821+
if (len > (APR_SIZE_MAX - 1) / 2) {
1822+
abort();
1823+
}
1824+
cmd = apr_palloc(p, 2 * len + 1);
18211825
d = (unsigned char *)cmd;
18221826
s = (const unsigned char *)str;
18231827
for (; *s; ++s) {

0 commit comments

Comments
 (0)