file: fix false positives for HTML because if zero length string compare, use image/p9bit as mimetype for plan9 bitmap

front
cinap_lenrek 2011-10-12 06:37:31 +02:00
parent 79589ef3fb
commit 2423c5a940
1 changed files with 16 additions and 15 deletions

View File

@ -923,7 +923,9 @@ iff(void)
char* html_string[] = char* html_string[] =
{ {
"?xml", "?xml",
"!doctype", "!--",
"![CDATA[",
"!DOCTYPE",
"html", "html",
"head", "head",
"title", "title",
@ -963,35 +965,34 @@ char* html_string[] =
int int
ishtml(void) ishtml(void)
{ {
uchar *p, *q; int i, n, count;
int i, count; uchar *p;
/* compare strings between '<' and '>' to html table */
count = 0; count = 0;
p = buf; p = buf;
for(;;) { for(;;) {
while (p < buf+nbuf && *p != '<') while(p < buf+nbuf && *p != '<')
p++; p++;
p++; p++;
if (p >= buf+nbuf) if (p >= buf+nbuf)
break; break;
if(*p == '/') if(*p == '/')
p++; p++;
q = p; if(p >= buf+nbuf)
while(p < buf+nbuf && isalpha(*p))
p++;
if (p >= buf+nbuf)
break; break;
for(i = 0; html_string[i]; i++) { for(i = 0; html_string[i]; i++){
if(cistrncmp(html_string[i], (char*)q, p-q) == 0) { n = strlen(html_string[i]);
if(p + n > buf+nbuf)
continue;
if(cistrncmp(html_string[i], (char*)p, n) == 0) {
if(++count > 2) { if(++count > 2) {
print(mime ? "text/html\n" : "HTML file\n"); print(mime ? "text/html\n" : "HTML file\n");
return 1; return 1;
} }
p += n;
break; break;
} }
} }
p++;
} }
return 0; return 0;
} }
@ -1348,7 +1349,7 @@ isp9bit(void)
* for subfont, the subfont header should follow immediately. * for subfont, the subfont header should follow immediately.
*/ */
if (cmpr) { if (cmpr) {
print(mime ? OCTET : "Compressed %splan 9 image or subfont, depth %d\n", print(mime ? "image/p9bit\n" : "Compressed %splan 9 image or subfont, depth %d\n",
newlabel, dep); newlabel, dep);
return 1; return 1;
} }
@ -1358,11 +1359,11 @@ isp9bit(void)
*/ */
if (len != 0 && (mbuf->length == 0 || mbuf->length == len || if (len != 0 && (mbuf->length == 0 || mbuf->length == len ||
mbuf->length > len && mbuf->length < len+P9BITLEN)) { mbuf->length > len && mbuf->length < len+P9BITLEN)) {
print(mime ? OCTET : "%splan 9 image, depth %d\n", newlabel, dep); print(mime ? "image/p9bit\n" : "%splan 9 image, depth %d\n", newlabel, dep);
return 1; return 1;
} }
if (p9subfont(buf+len)) { if (p9subfont(buf+len)) {
print(mime ? OCTET : "%ssubfont file, depth %d\n", newlabel, dep); print(mime ? "image/p9bit\n" : "%ssubfont file, depth %d\n", newlabel, dep);
return 1; return 1;
} }
return 0; return 0;