fix content type handling to not hard code (wrong) values for length,

but just call strlen() as needed.  call this 20150501.

reported by Jan Danielsson for ".svg".
This commit is contained in:
mrg 2015-05-02 11:35:48 +00:00
parent 5f99165065
commit 56ba1ad0cf
5 changed files with 145 additions and 146 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: bozohttpd.8,v 1.50 2015/04/16 02:32:33 mrg Exp $
.\" $NetBSD: bozohttpd.8,v 1.51 2015/05/02 11:35:48 mrg Exp $
.\"
.\" $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $
.\"
@ -26,7 +26,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd April 15, 2015
.Dd May 1, 2015
.Dt BOZOHTTPD 8
.Os
.Sh NAME
@ -510,7 +510,7 @@ The focus has always been simplicity and security, with minimal features
and regular code audits.
This manual documents
.Nm
version 20150320.
version 20150501.
.Sh AUTHORS
.An -nosplit
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: bozohttpd.c,v 1.63 2015/03/20 19:54:53 mrg Exp $ */
/* $NetBSD: bozohttpd.c,v 1.64 2015/05/02 11:35:48 mrg Exp $ */
/* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */
@ -109,7 +109,7 @@
#define INDEX_HTML "index.html"
#endif
#ifndef SERVER_SOFTWARE
#define SERVER_SOFTWARE "bozohttpd/20150320"
#define SERVER_SOFTWARE "bozohttpd/20150501"
#endif
#ifndef DIRECT_ACCESS_FILE
#define DIRECT_ACCESS_FILE ".bzdirect"
@ -1861,6 +1861,7 @@ static struct errors_map {
{ 404, "404 Not Found", "This item has not been found", },
{ 408, "408 Request Timeout", "This request took too long", },
{ 417, "417 Expectation Failed","Expectations not available", },
{ 420, "420 Enhance Your Calm","Chill, Winston", },
{ 500, "500 Internal Error", "An error occured on the server", },
{ 501, "501 Not Implemented", "This request is not available", },
{ 0, NULL, NULL, },

View File

@ -1,9 +1,9 @@
/* $NetBSD: bozohttpd.h,v 1.34 2014/11/21 08:58:28 shm Exp $ */
/* $NetBSD: bozohttpd.h,v 1.35 2015/05/02 11:35:48 mrg Exp $ */
/* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */
/*
* Copyright (c) 1997-2014 Matthew R. Green
* Copyright (c) 1997-2015 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -68,7 +68,6 @@ typedef struct lua_state_map {
typedef struct bozo_content_map_t {
const char *name; /* postfix of file */
size_t namelen; /* length of postfix */
const char *type; /* matching content-type */
const char *encoding; /* matching content-encoding */
const char *encoding11; /* matching content-encoding (HTTP/1.1) */

View File

@ -1,9 +1,9 @@
/* $NetBSD: cgi-bozo.c,v 1.26 2015/04/19 19:05:19 christos Exp $ */
/* $NetBSD: cgi-bozo.c,v 1.27 2015/05/02 11:35:48 mrg Exp $ */
/* $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $ */
/*
* Copyright (c) 1997-2014 Matthew R. Green
* Copyright (c) 1997-2015 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -515,7 +515,6 @@ bozo_add_content_map_cgi(bozohttpd_t *httpd, const char *arg, const char *cgihan
map = bozo_get_content_map(httpd, arg);
map->name = arg;
map->namelen = strlen(map->name);
map->type = map->encoding = map->encoding11 = NULL;
map->cgihandler = cgihandler;
}

View File

@ -1,9 +1,9 @@
/* $NetBSD: content-bozo.c,v 1.11 2014/12/13 19:30:04 mrg Exp $ */
/* $NetBSD: content-bozo.c,v 1.12 2015/05/02 11:35:48 mrg Exp $ */
/* $eterna: content-bozo.c,v 1.17 2011/11/18 09:21:15 mrg Exp $ */
/*
* Copyright (c) 1997-2014 Matthew R. Green
* Copyright (c) 1997-2015 Matthew R. Green
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -47,143 +47,145 @@
*/
static bozo_content_map_t static_content_map[] = {
{ ".html", 5, "text/html", "", "", NULL },
{ ".htm", 4, "text/html", "", "", NULL },
{ ".gif", 4, "image/gif", "", "", NULL },
{ ".jpeg", 5, "image/jpeg", "", "", NULL },
{ ".jpg", 4, "image/jpeg", "", "", NULL },
{ ".jpe", 4, "image/jpeg", "", "", NULL },
{ ".png", 4, "image/png", "", "", NULL },
{ ".mp3", 4, "audio/mpeg", "", "", NULL },
{ ".css", 4, "text/css", "", "", NULL },
{ ".txt", 4, "text/plain", "", "", NULL },
{ ".swf", 4, "application/x-shockwave-flash","", "", NULL },
{ ".dcr", 4, "application/x-director", "", "", NULL },
{ ".pac", 4, "application/x-ns-proxy-autoconfig", "", "", NULL },
{ ".pa", 3, "application/x-ns-proxy-autoconfig", "", "", NULL },
{ ".tar", 4, "multipart/x-tar", "", "", NULL },
{ ".gtar", 5, "multipart/x-gtar", "", "", NULL },
{ ".tar.Z", 6, "multipart/x-tar", "x-compress", "compress", NULL },
{ ".tar.gz", 7, "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".taz", 4, "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".tgz", 4, "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".tar.z", 6, "multipart/x-tar", "x-pack", "x-pack", NULL },
{ ".Z", 2, "application/x-compress", "x-compress", "compress", NULL },
{ ".gz", 3, "application/x-gzip", "x-gzip", "gzip", NULL },
{ ".z", 2, "unknown", "x-pack", "x-pack", NULL },
{ ".bz2", 4, "application/x-bzip2", "x-bzip2", "x-bzip2", NULL },
{ ".ogg", 4, "application/x-ogg", "", "", NULL },
{ ".mkv", 4, "video/x-matroska", "", "", NULL },
{ ".xbel", 5, "text/xml", "", "", NULL },
{ ".xml", 4, "text/xml", "", "", NULL },
{ ".xsl", 4, "text/xml", "", "", NULL },
{ ".hqx", 4, "application/mac-binhex40", "", "", NULL },
{ ".cpt", 4, "application/mac-compactpro","", "", NULL },
{ ".doc", 4, "application/msword", "", "", NULL },
{ ".bin", 4, "application/octet-stream", "", "", NULL },
{ ".dms", 4, "application/octet-stream", "", "", NULL },
{ ".lha", 4, "application/octet-stream", "", "", NULL },
{ ".lzh", 4, "application/octet-stream", "", "", NULL },
{ ".exe", 4, "application/octet-stream", "", "", NULL },
{ ".class", 6, "application/octet-stream", "", "", NULL },
{ ".oda", 4, "application/oda", "", "", NULL },
{ ".pdf", 4, "application/pdf", "", "", NULL },
{ ".ai", 3, "application/postscript", "", "", NULL },
{ ".eps", 4, "application/postscript", "", "", NULL },
{ ".ps", 3, "application/postscript", "", "", NULL },
{ ".ppt", 4, "application/powerpoint", "", "", NULL },
{ ".rtf", 4, "application/rtf", "", "", NULL },
{ ".bcpio", 6, "application/x-bcpio", "", "", NULL },
{ ".torrent", 8, "application/x-bittorrent", "", "", NULL },
{ ".vcd", 4, "application/x-cdlink", "", "", NULL },
{ ".cpio", 5, "application/x-cpio", "", "", NULL },
{ ".csh", 4, "application/x-csh", "", "", NULL },
{ ".dir", 4, "application/x-director", "", "", NULL },
{ ".dxr", 4, "application/x-director", "", "", NULL },
{ ".dvi", 4, "application/x-dvi", "", "", NULL },
{ ".hdf", 4, "application/x-hdf", "", "", NULL },
{ ".cgi", 4, "application/x-httpd-cgi", "", "", NULL },
{ ".skp", 4, "application/x-koan", "", "", NULL },
{ ".skd", 4, "application/x-koan", "", "", NULL },
{ ".skt", 4, "application/x-koan", "", "", NULL },
{ ".skm", 4, "application/x-koan", "", "", NULL },
{ ".latex", 6, "application/x-latex", "", "", NULL },
{ ".mif", 4, "application/x-mif", "", "", NULL },
{ ".nc", 3, "application/x-netcdf", "", "", NULL },
{ ".cdf", 4, "application/x-netcdf", "", "", NULL },
{ ".patch", 6, "application/x-patch", "", "", NULL },
{ ".sh", 3, "application/x-sh", "", "", NULL },
{ ".shar", 5, "application/x-shar", "", "", NULL },
{ ".sit", 4, "application/x-stuffit", "", "", NULL },
{ ".sv4cpio", 8, "application/x-sv4cpio", "", "", NULL },
{ ".sv4crc", 7, "application/x-sv4crc", "", "", NULL },
{ ".tar", 4, "application/x-tar", "", "", NULL },
{ ".tcl", 4, "application/x-tcl", "", "", NULL },
{ ".tex", 4, "application/x-tex", "", "", NULL },
{ ".texinfo", 8, "application/x-texinfo", "", "", NULL },
{ ".texi", 5, "application/x-texinfo", "", "", NULL },
{ ".t", 2, "application/x-troff", "", "", NULL },
{ ".tr", 3, "application/x-troff", "", "", NULL },
{ ".roff", 5, "application/x-troff", "", "", NULL },
{ ".man", 4, "application/x-troff-man", "", "", NULL },
{ ".me", 3, "application/x-troff-me", "", "", NULL },
{ ".ms", 3, "application/x-troff-ms", "", "", NULL },
{ ".ustar", 6, "application/x-ustar", "", "", NULL },
{ ".src", 4, "application/x-wais-source", "", "", NULL },
{ ".zip", 4, "application/zip", "", "", NULL },
{ ".au", 3, "audio/basic", "", "", NULL },
{ ".snd", 4, "audio/basic", "", "", NULL },
{ ".mpga", 5, "audio/mpeg", "", "", NULL },
{ ".mp2", 4, "audio/mpeg", "", "", NULL },
{ ".aif", 4, "audio/x-aiff", "", "", NULL },
{ ".aiff", 5, "audio/x-aiff", "", "", NULL },
{ ".aifc", 5, "audio/x-aiff", "", "", NULL },
{ ".ram", 4, "audio/x-pn-realaudio", "", "", NULL },
{ ".rpm", 4, "audio/x-pn-realaudio-plugin","", "", NULL },
{ ".ra", 3, "audio/x-realaudio", "", "", NULL },
{ ".wav", 4, "audio/x-wav", "", "", NULL },
{ ".pdb", 4, "chemical/x-pdb", "", "", NULL },
{ ".xyz", 4, "chemical/x-pdb", "", "", NULL },
{ ".ief", 4, "image/ief", "", "", NULL },
{ ".tiff", 5, "image/tiff", "", "", NULL },
{ ".tif", 4, "image/tiff", "", "", NULL },
{ ".ras", 4, "image/x-cmu-raster", "", "", NULL },
{ ".pnm", 4, "image/x-portable-anymap", "", "", NULL },
{ ".pbm", 4, "image/x-portable-bitmap", "", "", NULL },
{ ".pgm", 4, "image/x-portable-graymap", "", "", NULL },
{ ".ppm", 4, "image/x-portable-pixmap", "", "", NULL },
{ ".rgb", 4, "image/x-rgb", "", "", NULL },
{ ".xbm", 4, "image/x-xbitmap", "", "", NULL },
{ ".xpm", 4, "image/x-xpixmap", "", "", NULL },
{ ".xwd", 4, "image/x-xwindowdump", "", "", NULL },
{ ".rtx", 4, "text/richtext", "", "", NULL },
{ ".tsv", 4, "text/tab-separated-values", "", "", NULL },
{ ".etx", 4, "text/x-setext", "", "", NULL },
{ ".sgml", 5, "text/x-sgml", "", "", NULL },
{ ".sgm", 4, "text/x-sgml", "", "", NULL },
{ ".mpeg", 5, "video/mpeg", "", "", NULL },
{ ".mpg", 4, "video/mpeg", "", "", NULL },
{ ".mpe", 4, "video/mpeg", "", "", NULL },
{ ".ts", 4, "video/mpeg", "", "", NULL },
{ ".vob", 4, "video/mpeg", "", "", NULL },
{ ".mp4", 4, "video/mp4", "", "", NULL },
{ ".qt", 3, "video/quicktime", "", "", NULL },
{ ".mov", 4, "video/quicktime", "", "", NULL },
{ ".avi", 4, "video/x-msvideo", "", "", NULL },
{ ".movie", 6, "video/x-sgi-movie", "", "", NULL },
{ ".ice", 4, "x-conference/x-cooltalk", "", "", NULL },
{ ".wrl", 4, "x-world/x-vrml", "", "", NULL },
{ ".vrml", 5, "x-world/x-vrml", "", "", NULL },
{ ".svg", 5, "image/svg+xml", "", "", NULL },
{ NULL, 0, NULL, NULL, NULL, NULL }
{ ".html", "text/html", "", "", NULL },
{ ".htm", "text/html", "", "", NULL },
{ ".gif", "image/gif", "", "", NULL },
{ ".jpeg", "image/jpeg", "", "", NULL },
{ ".jpg", "image/jpeg", "", "", NULL },
{ ".jpe", "image/jpeg", "", "", NULL },
{ ".png", "image/png", "", "", NULL },
{ ".mp3", "audio/mpeg", "", "", NULL },
{ ".css", "text/css", "", "", NULL },
{ ".txt", "text/plain", "", "", NULL },
{ ".swf", "application/x-shockwave-flash","", "", NULL },
{ ".dcr", "application/x-director", "", "", NULL },
{ ".pac", "application/x-ns-proxy-autoconfig", "", "", NULL },
{ ".pa", "application/x-ns-proxy-autoconfig", "", "", NULL },
{ ".tar", "multipart/x-tar", "", "", NULL },
{ ".gtar", "multipart/x-gtar", "", "", NULL },
{ ".tar.Z", "multipart/x-tar", "x-compress", "compress", NULL },
{ ".tar.gz", "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".taz", "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".tgz", "multipart/x-tar", "x-gzip", "gzip", NULL },
{ ".tar.z", "multipart/x-tar", "x-pack", "x-pack", NULL },
{ ".Z", "application/x-compress", "x-compress", "compress", NULL },
{ ".gz", "application/x-gzip", "x-gzip", "gzip", NULL },
{ ".z", "unknown", "x-pack", "x-pack", NULL },
{ ".bz2", "application/x-bzip2", "x-bzip2", "x-bzip2", NULL },
{ ".ogg", "application/x-ogg", "", "", NULL },
{ ".mkv", "video/x-matroska", "", "", NULL },
{ ".xbel", "text/xml", "", "", NULL },
{ ".xml", "text/xml", "", "", NULL },
{ ".xsl", "text/xml", "", "", NULL },
{ ".hqx", "application/mac-binhex40", "", "", NULL },
{ ".cpt", "application/mac-compactpro", "", "", NULL },
{ ".doc", "application/msword", "", "", NULL },
{ ".bin", "application/octet-stream", "", "", NULL },
{ ".dms", "application/octet-stream", "", "", NULL },
{ ".lha", "application/octet-stream", "", "", NULL },
{ ".lzh", "application/octet-stream", "", "", NULL },
{ ".exe", "application/octet-stream", "", "", NULL },
{ ".class", "application/octet-stream", "", "", NULL },
{ ".oda", "application/oda", "", "", NULL },
{ ".pdf", "application/pdf", "", "", NULL },
{ ".ai", "application/postscript", "", "", NULL },
{ ".eps", "application/postscript", "", "", NULL },
{ ".ps", "application/postscript", "", "", NULL },
{ ".ppt", "application/powerpoint", "", "", NULL },
{ ".rtf", "application/rtf", "", "", NULL },
{ ".bcpio", "application/x-bcpio", "", "", NULL },
{ ".torrent", "application/x-bittorrent", "", "", NULL },
{ ".vcd", "application/x-cdlink", "", "", NULL },
{ ".cpio", "application/x-cpio", "", "", NULL },
{ ".csh", "application/x-csh", "", "", NULL },
{ ".dir", "application/x-director", "", "", NULL },
{ ".dxr", "application/x-director", "", "", NULL },
{ ".dvi", "application/x-dvi", "", "", NULL },
{ ".hdf", "application/x-hdf", "", "", NULL },
{ ".cgi", "application/x-httpd-cgi", "", "", NULL },
{ ".skp", "application/x-koan", "", "", NULL },
{ ".skd", "application/x-koan", "", "", NULL },
{ ".skt", "application/x-koan", "", "", NULL },
{ ".skm", "application/x-koan", "", "", NULL },
{ ".latex", "application/x-latex", "", "", NULL },
{ ".mif", "application/x-mif", "", "", NULL },
{ ".nc", "application/x-netcdf", "", "", NULL },
{ ".cdf", "application/x-netcdf", "", "", NULL },
{ ".patch", "application/x-patch", "", "", NULL },
{ ".sh", "application/x-sh", "", "", NULL },
{ ".shar", "application/x-shar", "", "", NULL },
{ ".sit", "application/x-stuffit", "", "", NULL },
{ ".sv4cpio", "application/x-sv4cpio", "", "", NULL },
{ ".sv4crc", "application/x-sv4crc", "", "", NULL },
{ ".tar", "application/x-tar", "", "", NULL },
{ ".tcl", "application/x-tcl", "", "", NULL },
{ ".tex", "application/x-tex", "", "", NULL },
{ ".texinfo", "application/x-texinfo", "", "", NULL },
{ ".texi", "application/x-texinfo", "", "", NULL },
{ ".t", "application/x-troff", "", "", NULL },
{ ".tr", "application/x-troff", "", "", NULL },
{ ".roff", "application/x-troff", "", "", NULL },
{ ".man", "application/x-troff-man", "", "", NULL },
{ ".me", "application/x-troff-me", "", "", NULL },
{ ".ms", "application/x-troff-ms", "", "", NULL },
{ ".ustar", "application/x-ustar", "", "", NULL },
{ ".src", "application/x-wais-source", "", "", NULL },
{ ".zip", "application/zip", "", "", NULL },
{ ".au", "audio/basic", "", "", NULL },
{ ".snd", "audio/basic", "", "", NULL },
{ ".mpga", "audio/mpeg", "", "", NULL },
{ ".mp2", "audio/mpeg", "", "", NULL },
{ ".aif", "audio/x-aiff", "", "", NULL },
{ ".aiff", "audio/x-aiff", "", "", NULL },
{ ".aifc", "audio/x-aiff", "", "", NULL },
{ ".ram", "audio/x-pn-realaudio", "", "", NULL },
{ ".rpm", "audio/x-pn-realaudio-plugin", "", "", NULL },
{ ".ra", "audio/x-realaudio", "", "", NULL },
{ ".wav", "audio/x-wav", "", "", NULL },
{ ".pdb", "chemical/x-pdb", "", "", NULL },
{ ".xyz", "chemical/x-pdb", "", "", NULL },
{ ".ief", "image/ief", "", "", NULL },
{ ".tiff", "image/tiff", "", "", NULL },
{ ".tif", "image/tiff", "", "", NULL },
{ ".ras", "image/x-cmu-raster", "", "", NULL },
{ ".pnm", "image/x-portable-anymap", "", "", NULL },
{ ".pbm", "image/x-portable-bitmap", "", "", NULL },
{ ".pgm", "image/x-portable-graymap", "", "", NULL },
{ ".ppm", "image/x-portable-pixmap", "", "", NULL },
{ ".rgb", "image/x-rgb", "", "", NULL },
{ ".xbm", "image/x-xbitmap", "", "", NULL },
{ ".xpm", "image/x-xpixmap", "", "", NULL },
{ ".xwd", "image/x-xwindowdump", "", "", NULL },
{ ".rtx", "text/richtext", "", "", NULL },
{ ".tsv", "text/tab-separated-values", "", "", NULL },
{ ".etx", "text/x-setext", "", "", NULL },
{ ".sgml", "text/x-sgml", "", "", NULL },
{ ".sgm", "text/x-sgml", "", "", NULL },
{ ".mpeg", "video/mpeg", "", "", NULL },
{ ".mpg", "video/mpeg", "", "", NULL },
{ ".mpe", "video/mpeg", "", "", NULL },
{ ".ts", "video/mpeg", "", "", NULL },
{ ".vob", "video/mpeg", "", "", NULL },
{ ".mp4", "video/mp4", "", "", NULL },
{ ".qt", "video/quicktime", "", "", NULL },
{ ".mov", "video/quicktime", "", "", NULL },
{ ".avi", "video/x-msvideo", "", "", NULL },
{ ".movie", "video/x-sgi-movie", "", "", NULL },
{ ".ice", "x-conference/x-cooltalk", "", "", NULL },
{ ".wrl", "x-world/x-vrml", "", "", NULL },
{ ".vrml", "x-world/x-vrml", "", "", NULL },
{ ".svg", "image/svg+xml", "", "", NULL },
{ NULL, NULL, NULL, NULL, NULL }
};
static bozo_content_map_t *
search_map(bozo_content_map_t *map, const char *name, size_t len)
{
for ( ; map && map->name; map++) {
if (map->namelen < len &&
strcasecmp(map->name, name + (len - map->namelen)) == 0)
const size_t namelen = strlen(map->name);
if (namelen < len &&
strcasecmp(map->name, name + (len - namelen)) == 0)
return map;
}
return NULL;
@ -260,7 +262,6 @@ bozo_get_content_map(bozohttpd_t *httpd, const char *name)
map = &httpd->dynamic_content_map[httpd->dynamic_content_map_size];
map->name = map->type = map->encoding = map->encoding11 =
map->cgihandler = NULL;
map->namelen = 0;
map--;
return map;
@ -291,7 +292,6 @@ bozo_add_content_map_mime(bozohttpd_t *httpd, const char *cmap0,
map = bozo_get_content_map(httpd, cmap0);
#define CHECKMAP(s) (!s || ((s)[0] == '-' && (s)[1] == '\0') ? "" : (s))
map->name = CHECKMAP(cmap0);
map->namelen = strlen(map->name);
map->type = CHECKMAP(cmap1);
map->encoding = CHECKMAP(cmap2);
map->encoding11 = CHECKMAP(cmap3);