Skip to content

Commit

Permalink
Merge pull request #40 from alex-vlasov/BR-6769
Browse files Browse the repository at this point in the history
BR-6769: memcmp in instance_only_subdir() causing segfault
  • Loading branch information
jpackagejasonc authored Mar 4, 2019
2 parents 77aa1b2 + a2df9bd commit aff9ab6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,15 @@ PHP_FUNCTION(shadow_clear_cache)
*/
static int instance_only_subdir(const char *dir TSRMLS_DC)
{
int i;
if(SHADOW_G(instance_only) == NULL) {
return 0;
}
int i;
int dir_len = strlen(dir);
for(i=0;i<SHADOW_G(instance_only_count);i++) {
/* TODO: optimize strlen here */
int len = strlen(SHADOW_G(instance_only)[i]);
if(memcmp(dir, SHADOW_G(instance_only)[i], len) == 0 && (!dir[len] || IS_SLASH(dir[len]))) {
if((dir_len >= len) && (memcmp(dir, SHADOW_G(instance_only)[i], len) == 0) && (!dir[len] || IS_SLASH(dir[len]))) {
return 1;
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/getconfig.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ array(3) {
["instance"]=>
string(%d) "%s/instance"
["instance_only"]=>
array(2) {
array(3) {
[0]=>
string(5) "cache"
[1]=>
string(6) "custom"
[2]=>
string(31) "custom/some/long/directory/name"
}
}
2 changes: 1 addition & 1 deletion tests/setup.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ set_include_path(
);

chdir($topdir);
shadow($template, $instance, array("cache", "custom")) || die("failed to setup shadow");
shadow($template, $instance, array("cache", "custom", "custom/some/long/directory/name")) || die("failed to setup shadow");
4 changes: 3 additions & 1 deletion tests/shadow_settings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ array(3) {
["instance"]=>
string(%d) "%s"
["instance_only"]=>
array(2) {
array(3) {
[0]=>
string(5) "cache"
[1]=>
string(6) "custom"
[2]=>
string(31) "custom/some/long/directory/name"
}
}
0755
Expand Down

0 comments on commit aff9ab6

Please sign in to comment.