Skip to content

Commit 120554b

Browse files
committed
more sync with orig lib
1 parent 52ff389 commit 120554b

File tree

4 files changed

+14
-153
lines changed

4 files changed

+14
-153
lines changed

ext/fileinfo/libmagic/cdf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ main(int argc, char *argv[])
15301530
== -1)
15311531
err(1, "Cannot read short stream");
15321532
#ifdef CDF_DEBUG
1533-
cdf_dump_stream(&h, &sst);
1533+
cdf_dump_stream(&sst);
15341534
#endif
15351535

15361536
#ifdef CDF_DEBUG

ext/fileinfo/libmagic/magic.c

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -92,138 +92,6 @@ private const char *file_or_stream(struct magic_set *, const char *, php_stream
9292
#define STDIN_FILENO 0
9393
#endif
9494

95-
/* XXX this functionality is excluded in php, enable it in apprentice.c:340 */
96-
#if 0
97-
private const char *
98-
get_default_magic(void)
99-
{
100-
static const char hmagic[] = "/.magic/magic.mgc";
101-
static char *default_magic;
102-
char *home, *hmagicpath;
103-
104-
#ifndef PHP_WIN32
105-
struct stat st;
106-
107-
if (default_magic) {
108-
free(default_magic);
109-
default_magic = NULL;
110-
}
111-
if ((home = getenv("HOME")) == NULL)
112-
return MAGIC;
113-
114-
if (asprintf(&hmagicpath, "%s/.magic.mgc", home) < 0)
115-
return MAGIC;
116-
if (stat(hmagicpath, &st) == -1) {
117-
free(hmagicpath);
118-
if (asprintf(&hmagicpath, "%s/.magic", home) < 0)
119-
return MAGIC;
120-
if (stat(hmagicpath, &st) == -1)
121-
goto out;
122-
if (S_ISDIR(st.st_mode)) {
123-
free(hmagicpath);
124-
if (asprintf(&hmagicpath, "%s/%s", home, hmagic) < 0)
125-
return MAGIC;
126-
if (access(hmagicpath, R_OK) == -1)
127-
goto out;
128-
}
129-
}
130-
131-
if (asprintf(&default_magic, "%s:%s", hmagicpath, MAGIC) < 0)
132-
goto out;
133-
free(hmagicpath);
134-
return default_magic;
135-
out:
136-
default_magic = NULL;
137-
free(hmagicpath);
138-
return MAGIC;
139-
#else
140-
char *hmagicp = hmagicpath;
141-
char *tmppath = NULL;
142-
LPTSTR dllpath;
143-
144-
#define APPENDPATH() \
145-
do { \
146-
if (tmppath && access(tmppath, R_OK) != -1) { \
147-
if (hmagicpath == NULL) \
148-
hmagicpath = tmppath; \
149-
else { \
150-
if (asprintf(&hmagicp, "%s%c%s", hmagicpath, \
151-
PATHSEP, tmppath) >= 0) { \
152-
free(hmagicpath); \
153-
hmagicpath = hmagicp; \
154-
} \
155-
free(tmppath); \
156-
} \
157-
tmppath = NULL; \
158-
} \
159-
} while (/*CONSTCOND*/0)
160-
161-
if (default_magic) {
162-
free(default_magic);
163-
default_magic = NULL;
164-
}
165-
166-
/* First, try to get user-specific magic file */
167-
if ((home = getenv("LOCALAPPDATA")) == NULL) {
168-
if ((home = getenv("USERPROFILE")) != NULL)
169-
if (asprintf(&tmppath,
170-
"%s/Local Settings/Application Data%s", home,
171-
hmagic) < 0)
172-
tmppath = NULL;
173-
} else {
174-
if (asprintf(&tmppath, "%s%s", home, hmagic) < 0)
175-
tmppath = NULL;
176-
}
177-
178-
APPENDPATH();
179-
180-
/* Second, try to get a magic file from Common Files */
181-
if ((home = getenv("COMMONPROGRAMFILES")) != NULL) {
182-
if (asprintf(&tmppath, "%s%s", home, hmagic) >= 0)
183-
APPENDPATH();
184-
}
185-
186-
/* Third, try to get magic file relative to dll location */
187-
dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));
188-
dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */
189-
if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){
190-
PathRemoveFileSpecA(dllpath);
191-
if (strlen(dllpath) > 3 &&
192-
stricmp(&dllpath[strlen(dllpath) - 3], "bin") == 0) {
193-
if (asprintf(&tmppath,
194-
"%s/../share/misc/magic.mgc", dllpath) >= 0)
195-
APPENDPATH();
196-
} else {
197-
if (asprintf(&tmppath,
198-
"%s/share/misc/magic.mgc", dllpath) >= 0)
199-
APPENDPATH();
200-
else if (asprintf(&tmppath,
201-
"%s/magic.mgc", dllpath) >= 0)
202-
APPENDPATH();
203-
}
204-
}
205-
206-
/* Don't put MAGIC constant - it likely points to a file within MSys
207-
tree */
208-
default_magic = hmagicpath;
209-
return default_magic;
210-
#endif
211-
}
212-
213-
public const char *
214-
magic_getpath(const char *magicfile, int action)
215-
{
216-
if (magicfile != NULL)
217-
return magicfile;
218-
219-
magicfile = getenv("MAGIC");
220-
if (magicfile != NULL)
221-
return magicfile;
222-
223-
return action == FILE_LOAD ? get_default_magic() : MAGIC;
224-
}
225-
#endif
226-
22795
public struct magic_set *
22896
magic_open(int flags)
22997
{

ext/fileinfo/libmagic/readcdf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static const struct cv {
9393
},
9494
{ { 0, 0 },
9595
NULL,
96-
}
96+
},
9797
}, clsid2desc[] = {
9898
{
9999
{ 0x00000000000c1084ULL, 0x46000000000000c0ULL },

ext/fileinfo/libmagic/softmagic.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,28 +1194,21 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
11941194
return 0;
11951195
}
11961196

1197-
/* bytecnt checks are to be kept for PHP, see cve-2014-3538.
1198-
PCRE might get stuck if the input buffer is too big. */
1199-
linecnt = m->str_range;
1200-
bytecnt = linecnt * 80;
1201-
1202-
if (bytecnt == 0) {
1203-
bytecnt = 1 << 14;
1197+
if (m->str_flags & REGEX_LINE_COUNT) {
1198+
linecnt = m->str_range;
1199+
bytecnt = linecnt * 80;
1200+
} else {
1201+
linecnt = 0;
1202+
bytecnt = m->str_range;
12041203
}
12051204

1206-
if (bytecnt > nbytes) {
1207-
bytecnt = nbytes;
1208-
}
1209-
if (offset > bytecnt) {
1210-
offset = bytecnt;
1211-
}
1212-
if (s == NULL) {
1213-
ms->search.s_len = 0;
1214-
ms->search.s = NULL;
1215-
return 0;
1216-
}
1205+
if (bytecnt == 0 || bytecnt > nbytes - offset)
1206+
bytecnt = nbytes - offset;
1207+
if (bytecnt > ms->regex_max)
1208+
bytecnt = ms->regex_max;
1209+
12171210
buf = RCAST(const char *, s) + offset;
1218-
end = last = RCAST(const char *, s) + bytecnt;
1211+
end = last = RCAST(const char *, s) + bytecnt + offset;
12191212
/* mget() guarantees buf <= last */
12201213
for (lines = linecnt, b = buf; lines && b < end &&
12211214
((b = CAST(const char *,

0 commit comments

Comments
 (0)