summaryrefslogtreecommitdiff
path: root/source3/lib/ms_fnmatch.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-09-14 22:03:41 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:30:48 -0500
commit3aaca8028e09db58381076f199a43680f81f04ac (patch)
treed9bbbe39fbfdd2b2db8462a156ee97dddf03cf9c /source3/lib/ms_fnmatch.c
parent5eb34f5d570b2370e010e81f65b53ce47a1a873d (diff)
downloadsamba-3aaca8028e09db58381076f199a43680f81f04ac.tar.gz
samba-3aaca8028e09db58381076f199a43680f81f04ac.tar.bz2
samba-3aaca8028e09db58381076f199a43680f81f04ac.zip
r25170: Remove pstring limits from ms_fnmatch and module load.
Jeremy. (This used to be commit 764574ee05ea4f13cdd30c0a0668ffeb81756989)
Diffstat (limited to 'source3/lib/ms_fnmatch.c')
-rw-r--r--source3/lib/ms_fnmatch.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c
index bdfaca143c..9dc942c5f2 100644
--- a/source3/lib/ms_fnmatch.c
+++ b/source3/lib/ms_fnmatch.c
@@ -1,4 +1,4 @@
-/*
+/*
Unix SMB/CIFS implementation.
filename matching routine
Copyright (C) Andrew Tridgell 1992-2004
@@ -7,21 +7,21 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This module was originally based on fnmatch.c copyright by the Free
Software Foundation. It bears little (if any) resemblence to that
code now
-*/
+*/
#include "includes.h"
@@ -53,7 +53,7 @@ struct max_n {
an optimisation only. The ldot pointer is NULL if the string does
not contain a '.', otherwise it points at the last dot in 'n'.
*/
-static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
+static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
struct max_n *max_n, const smb_ucs2_t *ldot,
BOOL is_case_sensitive)
{
@@ -137,22 +137,23 @@ static int ms_fnmatch_core(const smb_ucs2_t *p, const smb_ucs2_t *n,
break;
}
}
-
+
if (! *n) {
return 0;
}
-
+
return -1;
}
int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
BOOL is_case_sensitive)
{
- wpstring p, s;
+ smb_ucs2_t *p = NULL;
+ smb_ucs2_t *s = NULL;
int ret, count, i;
struct max_n *max_n = NULL;
- if (strcmp(string, "..") == 0) {
+ if (ISDOTDOT(string)) {
string = ".";
}
@@ -166,15 +167,12 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
}
}
- if (push_ucs2(NULL, p, pattern, sizeof(p), STR_TERMINATE) == (size_t)-1) {
- /* Not quite the right answer, but finding the right one
- under this failure case is expensive, and it's pretty close */
+ if (push_ucs2_allocate(&p, pattern) == (size_t)-1) {
return -1;
}
- if (push_ucs2(NULL, s, string, sizeof(s), STR_TERMINATE) == (size_t)-1) {
- /* Not quite the right answer, but finding the right one
- under this failure case is expensive, and it's pretty close */
+ if (push_ucs2_allocate(&s, string) == (size_t)-1) {
+ SAFE_FREE(p);
return -1;
}
@@ -187,8 +185,8 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
for (i=0;p[i];i++) {
if (p[i] == UCS2_CHAR('?')) {
p[i] = UCS2_CHAR('>');
- } else if (p[i] == UCS2_CHAR('.') &&
- (p[i+1] == UCS2_CHAR('?') ||
+ } else if (p[i] == UCS2_CHAR('.') &&
+ (p[i+1] == UCS2_CHAR('?') ||
p[i+1] == UCS2_CHAR('*') ||
p[i+1] == 0)) {
p[i] = UCS2_CHAR('"');
@@ -205,16 +203,17 @@ int ms_fnmatch(const char *pattern, const char *string, BOOL translate_pattern,
if (count != 0) {
max_n = SMB_CALLOC_ARRAY(struct max_n, count);
if (!max_n) {
+ SAFE_FREE(p);
+ SAFE_FREE(s);
return -1;
}
}
ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive);
- if (max_n) {
- free(max_n);
- }
-
+ SAFE_FREE(max_n);
+ SAFE_FREE(p);
+ SAFE_FREE(s);
return ret;
}