• R/O
  • SSH
  • HTTPS

caitsith: Commit


Commit MetaInfo

Revision167 (tree)
Time2015-08-04 21:36:55
Authorkumaneko

Log Message

Fix incorrect /\(dir\)/ pattern match.

Change Summary

Incremental Difference

--- trunk/caitsith-patch/security/caitsith/permission.c (revision 166)
+++ trunk/caitsith-patch/security/caitsith/permission.c (revision 167)
@@ -3718,58 +3718,39 @@
37183718 {
37193719 const char *f_delimiter;
37203720 const char *p_delimiter;
3721- char recursive_end;
37223721 while (*f && *p) {
3723- f_delimiter = strchr(f, '/');
3722+ f_delimiter = strchr(f + 1, '/');
37243723 if (!f_delimiter)
37253724 f_delimiter = f + strlen(f);
3726- p_delimiter = strchr(p, '/');
3725+ p_delimiter = strchr(p + 1, '/');
37273726 if (!p_delimiter)
37283727 p_delimiter = p + strlen(p);
3729- if (*p == '\\') {
3730- if (*(p + 1) == '{') {
3731- recursive_end = '}';
3732- goto recursive;
3728+ if (*p == '/' && *(p + 1) == '\\') {
3729+ if (*(p + 2) == '(') {
3730+ /* Check zero repetition. */
3731+ if (cs_path_matches_pattern2(f, p_delimiter))
3732+ return true;
3733+ /* Check one or more repetition. */
3734+ goto repetition;
37333735 }
3734- if (*(p + 1) == '(') {
3735- recursive_end = ')';
3736- goto recursive;
3737- }
3736+ if (*(p + 2) == '{')
3737+ goto repetition;
37383738 }
3739+ if ((*f == '/' || *p == '/') && *f++ != *p++)
3740+ return false;
37393741 if (!cs_file_matches_pattern(f, f_delimiter, p, p_delimiter))
37403742 return false;
37413743 f = f_delimiter;
3742- if (*f)
3743- f++;
37443744 p = p_delimiter;
3745- if (*p)
3746- p++;
37473745 }
37483746 /* Ignore trailing "\*" and "\@" in @pattern. */
3749- while (*p == '\\' &&
3750- (*(p + 1) == '*' || *(p + 1) == '@'))
3747+ while (*p == '\\' && (*(p + 1) == '*' || *(p + 1) == '@'))
37513748 p += 2;
37523749 return !*f && !*p;
3753-recursive:
3754- /*
3755- * The "\{" or "\(" pattern is permitted only after '/' character.
3756- * This guarantees that below "*(p - 1)" is safe.
3757- * Also, the "\}" or "\)" pattern is permitted only before '/'
3758- * character so that "\{" + "\}" or "\(" + "\)" pair will not break
3759- * the "\-" operator.
3760- */
3761- if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' ||
3762- *(p_delimiter - 1) != recursive_end || *(p_delimiter - 2) != '\\')
3763- return false; /* Bad pattern. */
3764- if (recursive_end == ')') {
3765- /* Check zero repetition. */
3766- if (cs_path_matches_pattern2(f, p_delimiter + 1))
3767- return true;
3768- /* Fall back to one or more repetition. */
3769- }
3750+repetition:
37703751 do {
37713752 /* Compare current component with pattern. */
3772- if (!cs_file_matches_pattern(f, f_delimiter, p + 2,
3753+ if (!cs_file_matches_pattern(f + 1, f_delimiter, p + 3,
37733754 p_delimiter - 2))
37743755 break;
37753756 /* Proceed to next component. */
@@ -3776,11 +3757,10 @@
37763757 f = f_delimiter;
37773758 if (!*f)
37783759 break;
3779- f++;
37803760 /* Continue comparison. */
3781- if (cs_path_matches_pattern2(f, p_delimiter + 1))
3761+ if (cs_path_matches_pattern2(f, p_delimiter))
37823762 return true;
3783- f_delimiter = strchr(f, '/');
3763+ f_delimiter = strchr(f + 1, '/');
37843764 } while (f_delimiter);
37853765 return false; /* Not matched. */
37863766 }
@@ -3823,23 +3803,11 @@
38233803 if (len == pattern->total_len)
38243804 return !cs_pathcmp(filename, pattern);
38253805 /* Compare the initial length without patterns. */
3826- if (strncmp(f, p, len))
3827- return false;
3828- f += len;
3829- p += len;
3830- /* Compare the last component first. */
3831- {
3832- const char *f2 = strrchr(f, '/');
3833- const char *p2 = strrchr(p, '/');
3834- if (!f2++)
3835- f2 = f;
3836- if (!p2++)
3837- p2 = p;
3838- if (!cs_file_matches_pattern(f2, filename->name
3839- + filename->total_len,
3840- p2, pattern->name
3841- + pattern->total_len))
3806+ if (len) {
3807+ if (strncmp(f, p, len))
38423808 return false;
3809+ f += len - 1;
3810+ p += len - 1;
38433811 }
38443812 return cs_path_matches_pattern2(f, p);
38453813 }
--- trunk/caitsith-patch/caitsith/permission.c (revision 166)
+++ trunk/caitsith-patch/caitsith/permission.c (revision 167)
@@ -3060,58 +3060,39 @@
30603060 {
30613061 const char *f_delimiter;
30623062 const char *p_delimiter;
3063- char recursive_end;
30643063 while (*f && *p) {
3065- f_delimiter = strchr(f, '/');
3064+ f_delimiter = strchr(f + 1, '/');
30663065 if (!f_delimiter)
30673066 f_delimiter = f + strlen(f);
3068- p_delimiter = strchr(p, '/');
3067+ p_delimiter = strchr(p + 1, '/');
30693068 if (!p_delimiter)
30703069 p_delimiter = p + strlen(p);
3071- if (*p == '\\') {
3072- if (*(p + 1) == '{') {
3073- recursive_end = '}';
3074- goto recursive;
3070+ if (*p == '/' && *(p + 1) == '\\') {
3071+ if (*(p + 2) == '(') {
3072+ /* Check zero repetition. */
3073+ if (cs_path_matches_pattern2(f, p_delimiter))
3074+ return true;
3075+ /* Check one or more repetition. */
3076+ goto repetition;
30753077 }
3076- if (*(p + 1) == '(') {
3077- recursive_end = ')';
3078- goto recursive;
3079- }
3078+ if (*(p + 2) == '{')
3079+ goto repetition;
30803080 }
3081+ if ((*f == '/' || *p == '/') && *f++ != *p++)
3082+ return false;
30813083 if (!cs_file_matches_pattern(f, f_delimiter, p, p_delimiter))
30823084 return false;
30833085 f = f_delimiter;
3084- if (*f)
3085- f++;
30863086 p = p_delimiter;
3087- if (*p)
3088- p++;
30893087 }
30903088 /* Ignore trailing "\*" and "\@" in @pattern. */
3091- while (*p == '\\' &&
3092- (*(p + 1) == '*' || *(p + 1) == '@'))
3089+ while (*p == '\\' && (*(p + 1) == '*' || *(p + 1) == '@'))
30933090 p += 2;
30943091 return !*f && !*p;
3095-recursive:
3096- /*
3097- * The "\{" or "\(" pattern is permitted only after '/' character.
3098- * This guarantees that below "*(p - 1)" is safe.
3099- * Also, the "\}" or "\)" pattern is permitted only before '/'
3100- * character so that "\{" + "\}" or "\(" + "\)" pair will not break
3101- * the "\-" operator.
3102- */
3103- if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' ||
3104- *(p_delimiter - 1) != recursive_end || *(p_delimiter - 2) != '\\')
3105- return false; /* Bad pattern. */
3106- if (recursive_end == ')') {
3107- /* Check zero repetition. */
3108- if (cs_path_matches_pattern2(f, p_delimiter + 1))
3109- return true;
3110- /* Fall back to one or more repetition. */
3111- }
3092+repetition:
31123093 do {
31133094 /* Compare current component with pattern. */
3114- if (!cs_file_matches_pattern(f, f_delimiter, p + 2,
3095+ if (!cs_file_matches_pattern(f + 1, f_delimiter, p + 3,
31153096 p_delimiter - 2))
31163097 break;
31173098 /* Proceed to next component. */
@@ -3118,11 +3099,10 @@
31183099 f = f_delimiter;
31193100 if (!*f)
31203101 break;
3121- f++;
31223102 /* Continue comparison. */
3123- if (cs_path_matches_pattern2(f, p_delimiter + 1))
3103+ if (cs_path_matches_pattern2(f, p_delimiter))
31243104 return true;
3125- f_delimiter = strchr(f, '/');
3105+ f_delimiter = strchr(f + 1, '/');
31263106 } while (f_delimiter);
31273107 return false; /* Not matched. */
31283108 }
@@ -3165,23 +3145,11 @@
31653145 if (len == pattern->total_len)
31663146 return !cs_pathcmp(filename, pattern);
31673147 /* Compare the initial length without patterns. */
3168- if (strncmp(f, p, len))
3169- return false;
3170- f += len;
3171- p += len;
3172- /* Compare the last component first. */
3173- {
3174- const char *f2 = strrchr(f, '/');
3175- const char *p2 = strrchr(p, '/');
3176- if (!f2++)
3177- f2 = f;
3178- if (!p2++)
3179- p2 = p;
3180- if (!cs_file_matches_pattern(f2, filename->name
3181- + filename->total_len,
3182- p2, pattern->name
3183- + pattern->total_len))
3148+ if (len) {
3149+ if (strncmp(f, p, len))
31843150 return false;
3151+ f += len - 1;
3152+ p += len - 1;
31853153 }
31863154 return cs_path_matches_pattern2(f, p);
31873155 }
Show on old repository browser