Module Name: src Committed By: mrg Date: Sun Dec 27 10:21:36 UTC 2015
Modified Files: src/libexec/httpd: auth-bozo.c bozohttpd.8 bozohttpd.c bozohttpd.h cgi-bozo.c dir-index-bozo.c lua-bozo.c main.c ssl-bozo.c tilde-luzah-bozo.c src/libexec/httpd/lua: glue.c Log Message: several clean ups: - bozostrdup() gains a request parameter, and uses it to determine what sort of error handling is required - bozo_strdup() dies - size_arrays() reduced slightly, pushing error handling into the caller - convert to size_t for some array indices - bozo_set_pref() and bozo_init_prefs() gain httpd parameters - apply a bunch of manual CSE to vastly reduce the number of times the string "request->hr_httpd" appears. - CGI parse_header() takes a request not httpd now XXX: lua glue updated to call bozo_init_prefs() with htttpd parameter, but i'm only guessing here. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/libexec/httpd/auth-bozo.c cvs rdiff -u -r1.57 -r1.58 src/libexec/httpd/bozohttpd.8 cvs rdiff -u -r1.72 -r1.73 src/libexec/httpd/bozohttpd.c cvs rdiff -u -r1.40 -r1.41 src/libexec/httpd/bozohttpd.h cvs rdiff -u -r1.28 -r1.29 src/libexec/httpd/cgi-bozo.c cvs rdiff -u -r1.22 -r1.23 src/libexec/httpd/dir-index-bozo.c cvs rdiff -u -r1.12 -r1.13 src/libexec/httpd/lua-bozo.c \ src/libexec/httpd/tilde-luzah-bozo.c cvs rdiff -u -r1.11 -r1.12 src/libexec/httpd/main.c cvs rdiff -u -r1.20 -r1.21 src/libexec/httpd/ssl-bozo.c cvs rdiff -u -r1.1.1.1 -r1.2 src/libexec/httpd/lua/glue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/libexec/httpd/auth-bozo.c diff -u src/libexec/httpd/auth-bozo.c:1.17 src/libexec/httpd/auth-bozo.c:1.18 --- src/libexec/httpd/auth-bozo.c:1.17 Wed Oct 28 09:20:15 2015 +++ src/libexec/httpd/auth-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: auth-bozo.c,v 1.17 2015/10/28 09:20:15 shm Exp $ */ +/* $NetBSD: auth-bozo.c,v 1.18 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: auth-bozo.c,v 1.17 2011/11/18 09:21:15 mrg Exp $ */ @@ -72,10 +72,10 @@ bozo_auth_check(bozo_httpreq_t *request, if (bozo_check_special_files(request, basename)) return 1; } - request->hr_authrealm = bozostrdup(httpd, dir); + request->hr_authrealm = bozostrdup(httpd, request, dir); - if ((size_t)snprintf(authfile, sizeof(authfile), "%s/%s", dir, AUTH_FILE) >= - sizeof(authfile)) { + if ((size_t)snprintf(authfile, sizeof(authfile), "%s/%s", dir, + AUTH_FILE) >= sizeof(authfile)) { return bozo_http_error(httpd, 404, request, "authfile path too long"); } @@ -136,7 +136,8 @@ bozo_auth_cleanup(bozo_httpreq_t *reques } int -bozo_auth_check_headers(bozo_httpreq_t *request, char *val, char *str, ssize_t len) +bozo_auth_check_headers(bozo_httpreq_t *request, char *val, char *str, + ssize_t len) { bozohttpd_t *httpd = request->hr_httpd; @@ -159,8 +160,8 @@ bozo_auth_check_headers(bozo_httpreq_t * *pass++ = '\0'; free(request->hr_authuser); free(request->hr_authpass); - request->hr_authuser = bozostrdup(httpd, authbuf); - request->hr_authpass = bozostrdup(httpd, pass); + request->hr_authuser = bozostrdup(httpd, request, authbuf); + request->hr_authpass = bozostrdup(httpd, request, pass); debug((httpd, DEBUG_FAT, "decoded authorization `%s' as `%s':`%s'", str, request->hr_authuser, request->hr_authpass)); @@ -190,7 +191,8 @@ bozo_auth_check_401(bozo_httpreq_t *requ if (code == 401) bozo_printf(httpd, "WWW-Authenticate: Basic realm=\"%s\"\r\n", - request->hr_authrealm ? request->hr_authrealm : "default realm"); + request->hr_authrealm ? + request->hr_authrealm : "default realm"); } #ifndef NO_CGIBIN_SUPPORT Index: src/libexec/httpd/bozohttpd.8 diff -u src/libexec/httpd/bozohttpd.8:1.57 src/libexec/httpd/bozohttpd.8:1.58 --- src/libexec/httpd/bozohttpd.8:1.57 Sat Dec 12 16:57:53 2015 +++ src/libexec/httpd/bozohttpd.8 Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -.\" $NetBSD: bozohttpd.8,v 1.57 2015/12/12 16:57:53 christos Exp $ +.\" $NetBSD: bozohttpd.8,v 1.58 2015/12/27 10:21:35 mrg Exp $ .\" .\" $eterna: bozohttpd.8,v 1.101 2011/11/18 01:25:11 mrg Exp $ .\" @@ -337,7 +337,8 @@ by default to process incoming TCP conne option), .Nm has little internal networking knowledge. -(Indeed, you can run it on the command line with little change of functionality.) +(Indeed, you can run it on the command line with little change of +functionality.) A typical .Xr inetd.conf 5 entry would be: Index: src/libexec/httpd/bozohttpd.c diff -u src/libexec/httpd/bozohttpd.c:1.72 src/libexec/httpd/bozohttpd.c:1.73 --- src/libexec/httpd/bozohttpd.c:1.72 Sat Dec 12 18:06:58 2015 +++ src/libexec/httpd/bozohttpd.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.c,v 1.72 2015/12/12 18:06:58 christos Exp $ */ +/* $NetBSD: bozohttpd.c,v 1.73 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */ @@ -171,61 +171,59 @@ volatile sig_atomic_t alarmhit; * check there's enough space in the prefs and names arrays. */ static int -size_arrays(bozoprefs_t *bozoprefs, unsigned needed) +size_arrays(bozoprefs_t *bozoprefs, size_t needed) { char **temp; if (bozoprefs->size == 0) { /* only get here first time around */ - bozoprefs->size = needed; - if ((bozoprefs->name = calloc(sizeof(char *), needed)) == NULL) { - (void) fprintf(stderr, "size_arrays: bad alloc\n"); + bozoprefs->name = calloc(sizeof(char *), needed); + if (bozoprefs->name == NULL) return 0; - } - if ((bozoprefs->value = calloc(sizeof(char *), needed)) == NULL) { + bozoprefs->value = calloc(sizeof(char *), needed); + if (bozoprefs->value == NULL) { free(bozoprefs->name); - (void) fprintf(stderr, "size_arrays: bad alloc\n"); return 0; } - } else if (bozoprefs->c == bozoprefs->size) { + bozoprefs->size = needed; + } else if (bozoprefs->count == bozoprefs->size) { /* only uses 'needed' when filled array */ - bozoprefs->size += needed; temp = realloc(bozoprefs->name, sizeof(char *) * needed); - if (temp == NULL) { - (void) fprintf(stderr, "size_arrays: bad alloc\n"); + if (temp == NULL) return 0; - } bozoprefs->name = temp; temp = realloc(bozoprefs->value, sizeof(char *) * needed); - if (temp == NULL) { - (void) fprintf(stderr, "size_arrays: bad alloc\n"); + if (temp == NULL) return 0; - } bozoprefs->value = temp; + bozoprefs->size += needed; } return 1; } -static int +static ssize_t findvar(bozoprefs_t *bozoprefs, const char *name) { - unsigned i; + size_t i; - for (i = 0 ; i < bozoprefs->c && strcmp(bozoprefs->name[i], name) != 0; i++) - ; - return (i == bozoprefs->c) ? -1 : (int)i; + for (i = 0; i < bozoprefs->count; i++) + if (strcmp(bozoprefs->name[i], name) == 0) + return (ssize_t)i; + return -1; } int -bozo_set_pref(bozoprefs_t *bozoprefs, const char *name, const char *value) +bozo_set_pref(bozohttpd_t *httpd, bozoprefs_t *bozoprefs, + const char *name, const char *value) { - int i; + ssize_t i; if ((i = findvar(bozoprefs, name)) < 0) { /* add the element to the array */ - if (size_arrays(bozoprefs, bozoprefs->size + 15)) { - bozoprefs->name[i = bozoprefs->c++] = strdup(name); - } + if (!size_arrays(bozoprefs, bozoprefs->size + 15)) + return 0; + i = bozoprefs->count++; + bozoprefs->name[i] = bozostrdup(httpd, NULL, name); } else { /* replace the element in the array */ if (bozoprefs->value[i]) { @@ -233,8 +231,7 @@ bozo_set_pref(bozoprefs_t *bozoprefs, co bozoprefs->value[i] = NULL; } } - /* sanity checks for range of values go here */ - bozoprefs->value[i] = strdup(value); + bozoprefs->value[i] = bozostrdup(httpd, NULL, value); return 1; } @@ -244,10 +241,10 @@ bozo_set_pref(bozoprefs_t *bozoprefs, co char * bozo_get_pref(bozoprefs_t *bozoprefs, const char *name) { - int i; + ssize_t i; - return ((i = findvar(bozoprefs, name)) < 0) ? NULL : - bozoprefs->value[i]; + i = findvar(bozoprefs, name); + return i < 0 ? NULL : bozoprefs->value[i]; } char * @@ -309,9 +306,9 @@ parse_request(bozohttpd_t *httpd, char * } /* allocate private copies */ - *file = bozostrdup(httpd, *file); + *file = bozostrdup(httpd, NULL, *file); if (*query) - *query = bozostrdup(httpd, *query); + *query = bozostrdup(httpd, NULL, *query); debug((httpd, DEBUG_FAT, "url: method: \"%s\" file: \"%s\" query: \"%s\" proto: \"%s\"", @@ -372,6 +369,7 @@ static bozoheaders_t * addmerge_header(bozo_httpreq_t *request, char *val, char *str, ssize_t len) { + struct bozohttpd_t *httpd = request->hr_httpd; struct bozoheaders *hdr; USE_ARG(len); @@ -386,7 +384,7 @@ addmerge_header(bozo_httpreq_t *request, char *nval; if (asprintf(&nval, "%s, %s", hdr->h_value, str) == -1) { - (void)bozo_http_error(request->hr_httpd, 500, NULL, + (void)bozo_http_error(httpd, 500, NULL, "memory allocation failure"); return NULL; } @@ -395,12 +393,12 @@ addmerge_header(bozo_httpreq_t *request, } else { /* nope, create a new one */ - hdr = bozomalloc(request->hr_httpd, sizeof *hdr); - hdr->h_header = bozostrdup(request->hr_httpd, val); + hdr = bozomalloc(httpd, sizeof *hdr); + hdr->h_header = bozostrdup(httpd, request, val); if (str && *str) - hdr->h_value = bozostrdup(request->hr_httpd, str); + hdr->h_value = bozostrdup(httpd, request, str); else - hdr->h_value = bozostrdup(request->hr_httpd, " "); + hdr->h_value = bozostrdup(httpd, request, " "); SIMPLEQ_INSERT_TAIL(&request->hr_headers, hdr, h_next); request->hr_nheaders++; @@ -416,13 +414,14 @@ addmerge_header(bozo_httpreq_t *request, static int process_proto(bozo_httpreq_t *request, const char *proto) { + struct bozohttpd_t *httpd = request->hr_httpd; char majorstr[16], *minorstr; int majorint, minorint; if (proto == NULL) { got_proto_09: - request->hr_proto = request->hr_httpd->consts.http_09; - debug((request->hr_httpd, DEBUG_FAT, "request %s is http/0.9", + request->hr_proto = httpd->consts.http_09; + debug((httpd, DEBUG_FAT, "request %s is http/0.9", request->hr_file)); return 0; } @@ -446,25 +445,25 @@ got_proto_09: goto got_proto_09; case 1: if (minorint == 0) - request->hr_proto = request->hr_httpd->consts.http_10; + request->hr_proto = httpd->consts.http_10; else if (minorint == 1) - request->hr_proto = request->hr_httpd->consts.http_11; + request->hr_proto = httpd->consts.http_11; else break; - debug((request->hr_httpd, DEBUG_FAT, "request %s is %s", + debug((httpd, DEBUG_FAT, "request %s is %s", request->hr_file, request->hr_proto)); SIMPLEQ_INIT(&request->hr_headers); request->hr_nheaders = 0; return 0; } bad: - return bozo_http_error(request->hr_httpd, 404, NULL, "unknown prototype"); + return bozo_http_error(httpd, 404, NULL, "unknown prototype"); } /* * process each type of HTTP method, setting this HTTP requests - # method type. + * method type. */ static struct method_map { const char *name; @@ -486,9 +485,10 @@ static struct method_map { static int process_method(bozo_httpreq_t *request, const char *method) { + struct bozohttpd_t *httpd = request->hr_httpd; struct method_map *mmp; - if (request->hr_proto == request->hr_httpd->consts.http_11) + if (request->hr_proto == httpd->consts.http_11) request->hr_allow = "GET, HEAD, POST"; for (mmp = method_map; mmp->name; mmp++) @@ -498,7 +498,7 @@ process_method(bozo_httpreq_t *request, return 0; } - return bozo_http_error(request->hr_httpd, 404, request, "unknown method"); + return bozo_http_error(httpd, 404, request, "unknown method"); } /* @@ -561,9 +561,9 @@ bozo_read_request(bozohttpd_t *httpd) host = NULL; } if (host != NULL) - request->hr_remotehost = bozostrdup(request->hr_httpd, host); + request->hr_remotehost = bozostrdup(httpd, request, host); if (addr != NULL) - request->hr_remoteaddr = bozostrdup(request->hr_httpd, addr); + request->hr_remoteaddr = bozostrdup(httpd, request, addr); slen = sizeof(ss); /* @@ -579,15 +579,16 @@ bozo_read_request(bozohttpd_t *httpd) if (getsockname(0, (struct sockaddr *)(void *)&ss, &slen) < 0) port = NULL; else { - if (getnameinfo((struct sockaddr *)(void *)&ss, slen, NULL, 0, - bufport, sizeof bufport, NI_NUMERICSERV) == 0) + if (getnameinfo((struct sockaddr *)(void *)&ss, slen, + NULL, 0, bufport, sizeof bufport, + NI_NUMERICSERV) == 0) port = bufport; else port = NULL; } } if (port != NULL) - request->hr_serverport = bozostrdup(request->hr_httpd, port); + request->hr_serverport = bozostrdup(httpd, request, port); /* * setup a timer to make sure the request is not hung @@ -615,11 +616,11 @@ bozo_read_request(bozohttpd_t *httpd) "null method"); goto cleanup; } - - bozo_warn(httpd, "got request ``%s'' from host %s to port %s", - str, - host ? host : addr ? addr : "<local>", - port ? port : "<stdin>"); + bozo_warn(httpd, + "got request ``%s'' from host %s to port %s", + str, + host ? host : addr ? addr : "<local>", + port ? port : "<stdin>"); /* we allocate return space in file and query only */ parse_request(httpd, str, &method, &file, &query, &proto); @@ -683,7 +684,8 @@ bozo_read_request(bozohttpd_t *httpd) else if (strcasecmp(hdr->h_header, "content-length") == 0) request->hr_content_length = hdr->h_value; else if (strcasecmp(hdr->h_header, "host") == 0) - request->hr_host = bozostrdup(httpd, hdr->h_value); + request->hr_host = bozostrdup(httpd, request, + hdr->h_value); /* RFC 2616 (HTTP/1.1): 14.20 */ else if (strcasecmp(hdr->h_header, "expect") == 0) { (void)bozo_http_error(httpd, 417, request, @@ -966,7 +968,7 @@ handle_redirect(bozo_httpreq_t *request, * RFC 3986, section 3.1: * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */ - if (sep != NULL) { + if (sep) { for (s = url; s != sep;) { if (!isalnum((int)*s) && *s != '+' && *s != '-' && *s != '.') @@ -978,7 +980,7 @@ handle_redirect(bozo_httpreq_t *request, } } - url = bozo_escape_rfc3986(request->hr_httpd, url, absolute); + url = bozo_escape_rfc3986(httpd, url, absolute); if (request->hr_query && strlen(request->hr_query)) query = 1; @@ -990,6 +992,7 @@ handle_redirect(bozo_httpreq_t *request, portbuf[0] = '\0'; /* construct final redirection url */ + /* XXX asprintf */ finalurl_len = strlen(url) + 1; if (!absproto) { /* add default schema */ @@ -1070,12 +1073,12 @@ check_virtual(bozo_httpreq_t *request) file += 7; /* RFC 2616 (HTTP/1.1), 5.2: URI takes precedence over Host: */ free(request->hr_host); - request->hr_host = bozostrdup(request->hr_httpd, file); + request->hr_host = bozostrdup(httpd, request, file); if ((s = strchr(request->hr_host, '/')) != NULL) *s = '\0'; s = strchr(file, '/'); free(request->hr_file); - request->hr_file = bozostrdup(request->hr_httpd, s ? s : "/"); + request->hr_file = bozostrdup(httpd, request, s ? s : "/"); debug((httpd, DEBUG_OBESE, "got host ``%s'' file is now ``%s''", request->hr_host, request->hr_file)); } else if (!request->hr_host) @@ -1103,7 +1106,7 @@ check_virtual(bozo_httpreq_t *request) if (s != NULL) /* truncate Host: as we want to copy it without port part */ *s = '\0'; - request->hr_virthostname = bozostrdup(request->hr_httpd, + request->hr_virthostname = bozostrdup(httpd, request, request->hr_host); if (s != NULL) /* fix Host: again, if we truncated it */ @@ -1140,7 +1143,7 @@ check_virtual(bozo_httpreq_t *request) /* found it, punch it */ debug((httpd, DEBUG_OBESE, "found it punch it")); request->hr_virthostname = - bozostrdup(httpd, d->d_name); + bozostrdup(httpd, request, d->d_name); bozo_asprintf(httpd, &s, "%s/%s", httpd->virtbase, request->hr_virthostname); @@ -1180,6 +1183,7 @@ use_slashdir: static int check_bzredirect(bozo_httpreq_t *request) { + bozohttpd_t *httpd = request->hr_httpd; struct stat sb; char dir[MAXPATHLEN], redir[MAXPATHLEN], redirpath[MAXPATHLEN + 1], path[MAXPATHLEN]; @@ -1192,11 +1196,11 @@ check_bzredirect(bozo_httpreq_t *request */ if((size_t)snprintf(dir, sizeof(dir), "%s", request->hr_file + 1) >= sizeof(dir)) { - bozo_http_error(request->hr_httpd, 404, request, + bozo_http_error(httpd, 404, request, "file path too long"); return -1; } - debug((request->hr_httpd, DEBUG_FAT, "check_bzredirect: dir %s", dir)); + debug((httpd, DEBUG_FAT, "check_bzredirect: dir %s", dir)); basename = strrchr(dir, '/'); if ((!basename || basename[1] != '\0') && @@ -1211,12 +1215,12 @@ check_bzredirect(bozo_httpreq_t *request strcpy(path, dir); } - debug((request->hr_httpd, DEBUG_FAT, "check_bzredirect: path %s", path)); + debug((httpd, DEBUG_FAT, "check_bzredirect: path %s", path)); if ((size_t)snprintf(redir, sizeof(redir), "%s/%s", path, REDIRECT_FILE) >= sizeof(redir)) { - bozo_http_error(request->hr_httpd, 404, request, - "redirectfile path too long"); + bozo_http_error(httpd, 404, request, + "redirectfile path too long"); return -1; } if (lstat(redir, &sb) == 0) { @@ -1226,7 +1230,7 @@ check_bzredirect(bozo_httpreq_t *request } else { if((size_t)snprintf(redir, sizeof(redir), "%s/%s", path, ABSREDIRECT_FILE) >= sizeof(redir)) { - bozo_http_error(request->hr_httpd, 404, request, + bozo_http_error(httpd, 404, request, "redirectfile path too long"); return -1; } @@ -1234,16 +1238,14 @@ check_bzredirect(bozo_httpreq_t *request return 0; absolute = 1; } - debug((request->hr_httpd, DEBUG_FAT, - "check_bzredirect: calling readlink")); + debug((httpd, DEBUG_FAT, "check_bzredirect: calling readlink")); rv = readlink(redir, redirpath, sizeof redirpath - 1); if (rv == -1 || rv == 0) { - debug((request->hr_httpd, DEBUG_FAT, "readlink failed")); + debug((httpd, DEBUG_FAT, "readlink failed")); return 0; } redirpath[rv] = '\0'; - debug((request->hr_httpd, DEBUG_FAT, - "readlink returned \"%s\"", redirpath)); + debug((httpd, DEBUG_FAT, "readlink returned \"%s\"", redirpath)); /* check if we need authentication */ snprintf(path, sizeof(path), "%s/", dir); @@ -1254,15 +1256,14 @@ check_bzredirect(bozo_httpreq_t *request if (!absolute && redirpath[0] != '/') { if ((size_t)snprintf(finalredir = redir, sizeof(redir), "%s%s/%s", (strlen(dir) > 0 ? "/" : ""), dir, redirpath) >= sizeof(redir)) { - bozo_http_error(request->hr_httpd, 404, request, + bozo_http_error(httpd, 404, request, "redirect path too long"); return -1; } } else finalredir = redirpath; - debug((request->hr_httpd, DEBUG_FAT, - "check_bzredirect: new redir %s", finalredir)); + debug((httpd, DEBUG_FAT, "check_bzredirect: new redir %s", finalredir)); handle_redirect(request, finalredir, absolute); return 1; } @@ -1428,10 +1429,10 @@ transform_request(bozo_httpreq_t *reques strcpy(newfile, file + 1); strcat(newfile, httpd->index_html); } else - newfile = bozostrdup(request->hr_httpd, file + 1); + newfile = bozostrdup(httpd, request, file + 1); } else if (len == 1) { debug((httpd, DEBUG_EXPLODING, "tf_req: len == 1")); - newfile = bozostrdup(request->hr_httpd, httpd->index_html); + newfile = bozostrdup(httpd, request, httpd->index_html); *isindex = 1; } else { /* len == 0 ? */ (void)bozo_http_error(httpd, 500, request, @@ -1790,18 +1791,6 @@ bozo_err(bozohttpd_t *httpd, int code, c exit(code); } -char * -bozo_strdup(bozohttpd_t *httpd, const char *str) -{ - char *p; - - p = strdup(str); - if (p == NULL) - bozo_err(httpd, EXIT_FAILURE, "strdup"); - - return p; -} - void bozo_asprintf(bozohttpd_t *httpd, char **str, const char *fmt, ...) { @@ -2129,12 +2118,11 @@ bozorealloc(bozohttpd_t *httpd, void *pt void *p; p = realloc(ptr, size); - if (p == NULL) { - (void)bozo_http_error(httpd, 500, NULL, - "memory allocation failure"); - exit(1); - } - return (p); + if (p) + return p; + + (void)bozo_http_error(httpd, 500, NULL, "memory allocation failure"); + exit(EXIT_FAILURE); } void * @@ -2143,26 +2131,27 @@ bozomalloc(bozohttpd_t *httpd, size_t si void *p; p = malloc(size); - if (p == NULL) { - (void)bozo_http_error(httpd, 500, NULL, - "memory allocation failure"); - exit(EXIT_FAILURE); - } - return (p); + if (p) + return p; + + (void)bozo_http_error(httpd, 500, NULL, "memory allocation failure"); + exit(EXIT_FAILURE); } char * -bozostrdup(bozohttpd_t *httpd, const char *str) +bozostrdup(bozohttpd_t *httpd, bozo_httpreq_t *request, const char *str) { char *p; p = strdup(str); - if (p == NULL) { - (void)bozo_http_error(httpd, 500, NULL, - "memory allocation failure"); - exit(EXIT_FAILURE); - } - return (p); + if (p) + return p; + + if (!request) + bozo_err(httpd, EXIT_FAILURE, "strdup"); + + (void)bozo_http_error(httpd, 500, request, "memory allocation failure"); + exit(EXIT_FAILURE); } /* set default values in bozohttpd_t struct */ @@ -2195,15 +2184,16 @@ bozo_init_httpd(bozohttpd_t *httpd) /* set default values in bozoprefs_t struct */ int -bozo_init_prefs(bozoprefs_t *prefs) +bozo_init_prefs(bozohttpd_t *httpd, bozoprefs_t *prefs) { /* make sure everything is clean */ (void) memset(prefs, 0x0, sizeof(*prefs)); /* set up default values */ - bozo_set_pref(prefs, "server software", SERVER_SOFTWARE); - bozo_set_pref(prefs, "index.html", INDEX_HTML); - bozo_set_pref(prefs, "public_html", PUBLIC_HTML); + if (!bozo_set_pref(httpd, prefs, "server software", SERVER_SOFTWARE) || + !bozo_set_pref(httpd, prefs, "index.html", INDEX_HTML) || + !bozo_set_pref(httpd, prefs, "public_html", PUBLIC_HTML)) + return 0; return 1; } @@ -2212,7 +2202,7 @@ bozo_init_prefs(bozoprefs_t *prefs) int bozo_set_defaults(bozohttpd_t *httpd, bozoprefs_t *prefs) { - return bozo_init_httpd(httpd) && bozo_init_prefs(prefs); + return bozo_init_httpd(httpd) && bozo_init_prefs(httpd, prefs); } /* set the virtual host name, port and root */ @@ -2239,11 +2229,11 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs bozo_err(httpd, 1, "gethostname"); httpd->virthostname[MAXHOSTNAMELEN] = '\0'; } else { - httpd->virthostname = bozo_strdup(httpd, vhost); + httpd->virthostname = bozostrdup(httpd, NULL, vhost); } - httpd->slashdir = bozo_strdup(httpd, root); + httpd->slashdir = bozostrdup(httpd, NULL, root); if ((portnum = bozo_get_pref(prefs, "port number")) != NULL) { - httpd->bindport = bozo_strdup(httpd, portnum); + httpd->bindport = bozostrdup(httpd, NULL, portnum); } /* go over preferences now */ @@ -2256,7 +2246,7 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs httpd->logstderr = 1; } if ((cp = bozo_get_pref(prefs, "bind address")) != NULL) { - httpd->bindaddress = bozo_strdup(httpd, cp); + httpd->bindaddress = bozostrdup(httpd, NULL, cp); } if ((cp = bozo_get_pref(prefs, "background")) != NULL) { httpd->background = atoi(cp); @@ -2266,14 +2256,14 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs httpd->foreground = 1; } if ((cp = bozo_get_pref(prefs, "pid file")) != NULL) { - httpd->pidfile = bozo_strdup(httpd, cp); + httpd->pidfile = bozostrdup(httpd, NULL, cp); } if ((cp = bozo_get_pref(prefs, "unknown slash")) != NULL && strcmp(cp, "true") == 0) { httpd->unknown_slash = 1; } if ((cp = bozo_get_pref(prefs, "virtual base")) != NULL) { - httpd->virtbase = bozo_strdup(httpd, cp); + httpd->virtbase = bozostrdup(httpd, NULL, cp); } if ((cp = bozo_get_pref(prefs, "enable users")) != NULL && strcmp(cp, "true") == 0) { @@ -2296,12 +2286,12 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs httpd->dir_indexing = 1; } if ((cp = bozo_get_pref(prefs, "public_html")) != NULL) { - httpd->public_html = bozo_strdup(httpd, cp); + httpd->public_html = bozostrdup(httpd, NULL, cp); } httpd->server_software = - bozo_strdup(httpd, bozo_get_pref(prefs, "server software")); + bozostrdup(httpd, NULL, bozo_get_pref(prefs, "server software")); httpd->index_html = - bozo_strdup(httpd, bozo_get_pref(prefs, "index.html")); + bozostrdup(httpd, NULL, bozo_get_pref(prefs, "index.html")); /* * initialise ssl and daemon mode if necessary. @@ -2312,9 +2302,9 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs if ((username = bozo_get_pref(prefs, "username")) == NULL) { if ((pw = getpwuid(uid = 0)) == NULL) bozo_err(httpd, 1, "getpwuid(0): %s", strerror(errno)); - httpd->username = bozo_strdup(httpd, pw->pw_name); + httpd->username = bozostrdup(httpd, NULL, pw->pw_name); } else { - httpd->username = bozo_strdup(httpd, username); + httpd->username = bozostrdup(httpd, NULL, username); if ((pw = getpwnam(httpd->username)) == NULL) bozo_err(httpd, 1, "getpwnam(%s): %s", httpd->username, strerror(errno)); @@ -2329,7 +2319,7 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs * handle chroot. */ if ((chrootdir = bozo_get_pref(prefs, "chroot dir")) != NULL) { - httpd->rootdir = bozo_strdup(httpd, chrootdir); + httpd->rootdir = bozostrdup(httpd, NULL, chrootdir); if (chdir(httpd->rootdir) == -1) bozo_err(httpd, 1, "chdir(%s): %s", httpd->rootdir, strerror(errno)); Index: src/libexec/httpd/bozohttpd.h diff -u src/libexec/httpd/bozohttpd.h:1.40 src/libexec/httpd/bozohttpd.h:1.41 --- src/libexec/httpd/bozohttpd.h:1.40 Sat Dec 12 18:06:58 2015 +++ src/libexec/httpd/bozohttpd.h Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: bozohttpd.h,v 1.40 2015/12/12 18:06:58 christos Exp $ */ +/* $NetBSD: bozohttpd.h,v 1.41 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */ @@ -184,8 +184,8 @@ typedef struct bozo_httpreq_t { /* structure to hold string based (name, value) pairs with preferences */ typedef struct bozoprefs_t { - unsigned size; /* size of the two arrays */ - unsigned c; /* # of entries in arrays */ + size_t size; /* size of the two arrays */ + size_t count; /* # of entries in arrays */ char **name; /* names of each entry */ char **value; /* values for the name entries */ } bozoprefs_t; @@ -225,22 +225,23 @@ void bozo_err(bozohttpd_t *, int, const BOZO_DEAD; void bozo_asprintf(bozohttpd_t *, char **, const char *, ...) BOZO_PRINTFLIKE(3, 4); -char *bozo_strdup(bozohttpd_t *, const char *); int bozo_http_error(bozohttpd_t *, int, bozo_httpreq_t *, const char *); int bozo_check_special_files(bozo_httpreq_t *, const char *); char *bozo_http_date(char *, size_t); -void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *, const char *); +void bozo_print_header(bozo_httpreq_t *, struct stat *, const char *, + const char *); char *bozo_escape_rfc3986(bozohttpd_t *httpd, const char *url, int absolute); char *bozo_escape_html(bozohttpd_t *httpd, const char *url); -char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *, int, void *, size_t)); +char *bozodgetln(bozohttpd_t *, int, ssize_t *, ssize_t (*)(bozohttpd_t *, + int, void *, size_t)); char *bozostrnsep(char **, const char *, ssize_t *); void *bozomalloc(bozohttpd_t *, size_t); void *bozorealloc(bozohttpd_t *, void *, size_t); -char *bozostrdup(bozohttpd_t *, const char *); +char *bozostrdup(bozohttpd_t *, bozo_httpreq_t *, const char *); #define bozo_noop do { /* nothing */ } while (/*CONSTCOND*/0) @@ -338,7 +339,8 @@ const char *bozo_content_encoding(bozo_h bozo_content_map_t *bozo_match_content_map(bozohttpd_t *, const char *, int); bozo_content_map_t *bozo_get_content_map(bozohttpd_t *, const char *); #ifndef NO_DYNAMIC_CONTENT -void bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *, const char *, const char *); +void bozo_add_content_map_mime(bozohttpd_t *, const char *, const char *, + const char *, const char *); #endif /* I/O */ @@ -349,7 +351,7 @@ int bozo_flush(bozohttpd_t *, FILE *); /* misc */ int bozo_init_httpd(bozohttpd_t *); -int bozo_init_prefs(bozoprefs_t *); +int bozo_init_prefs(bozohttpd_t *, bozoprefs_t *); int bozo_set_defaults(bozohttpd_t *, bozoprefs_t *); int bozo_setup(bozohttpd_t *, bozoprefs_t *, const char *, const char *); bozo_httpreq_t *bozo_read_request(bozohttpd_t *); @@ -357,7 +359,7 @@ void bozo_process_request(bozo_httpreq_t void bozo_clean_request(bozo_httpreq_t *); /* variables */ -int bozo_set_pref(bozoprefs_t *, const char *, const char *); +int bozo_set_pref(bozohttpd_t *, bozoprefs_t *, const char *, const char *); char *bozo_get_pref(bozoprefs_t *, const char *); #endif /* BOZOHTTOPD_H_ */ Index: src/libexec/httpd/cgi-bozo.c diff -u src/libexec/httpd/cgi-bozo.c:1.28 src/libexec/httpd/cgi-bozo.c:1.29 --- src/libexec/httpd/cgi-bozo.c:1.28 Wed Oct 28 09:20:15 2015 +++ src/libexec/httpd/cgi-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: cgi-bozo.c,v 1.28 2015/10/28 09:20:15 shm Exp $ */ +/* $NetBSD: cgi-bozo.c,v 1.29 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: cgi-bozo.c,v 1.40 2011/11/18 09:21:15 mrg Exp $ */ @@ -75,16 +75,17 @@ content_cgihandler(bozohttpd_t *httpd, b } static int -parse_header(bozohttpd_t *httpd, const char *str, ssize_t len, char **hdr_str, - char **hdr_val) +parse_header(bozo_httpreq_t *request, const char *str, ssize_t len, + char **hdr_str, char **hdr_val) { + struct bozohttpd_t *httpd = request->hr_httpd; char *name, *value; /* if the string passed is zero-length bail out */ if (*str == '\0') return -1; - value = bozostrdup(httpd, str); + value = bozostrdup(httpd, request, str); /* locate the ':' separator in the header/value */ name = bozostrnsep(&value, ":", &len); @@ -127,7 +128,7 @@ finish_cgi_output(bozohttpd_t *httpd, bo (str = bozodgetln(httpd, in, &len, bozo_read)) != NULL) { char *hdr_name, *hdr_value; - if (parse_header(httpd, str, len, &hdr_name, &hdr_value)) + if (parse_header(request, str, len, &hdr_name, &hdr_value)) break; /* @@ -214,7 +215,7 @@ append_index_html(bozohttpd_t *httpd, ch void bozo_cgi_setbin(bozohttpd_t *httpd, const char *path) { - httpd->cgibin = strdup(path); + httpd->cgibin = bozostrdup(httpd, NULL, path); debug((httpd, DEBUG_OBESE, "cgibin (cgi-bin directory) is %s", httpd->cgibin)); } @@ -271,14 +272,14 @@ bozo_process_cgi(bozo_httpreq_t *request uri = request->hr_file; if (uri[0] == '/') - file = bozostrdup(httpd, uri); + file = bozostrdup(httpd, request, uri); else asprintf(&file, "/%s", uri); if (file == NULL) return 0; if (request->hr_query && strlen(request->hr_query)) - query = bozostrdup(httpd, request->hr_query); + query = bozostrdup(httpd, request, request->hr_query); else query = NULL; @@ -315,14 +316,14 @@ bozo_process_cgi(bozo_httpreq_t *request ix = 0; if (cgihandler) { snprintf(command, sizeof(command), "%s", file + 1); - path = bozostrdup(httpd, cgihandler); + path = bozostrdup(httpd, request, cgihandler); argv[ix++] = path; /* argv[] = [ path, command, query, NULL ] */ } else { snprintf(command, sizeof(command), "%s", file + CGIBIN_PREFIX_LEN + 1); if ((s = strchr(command, '/')) != NULL) { - info = bozostrdup(httpd, s); + info = bozostrdup(httpd, request, s); *s = '\0'; } path = bozomalloc(httpd, @@ -509,7 +510,8 @@ bozo_process_cgi(bozo_httpreq_t *request #ifndef NO_DYNAMIC_CONTENT /* cgi maps are simple ".postfix /path/to/prog" */ void -bozo_add_content_map_cgi(bozohttpd_t *httpd, const char *arg, const char *cgihandler) +bozo_add_content_map_cgi(bozohttpd_t *httpd, const char *arg, + const char *cgihandler) { bozo_content_map_t *map; Index: src/libexec/httpd/dir-index-bozo.c diff -u src/libexec/httpd/dir-index-bozo.c:1.22 src/libexec/httpd/dir-index-bozo.c:1.23 --- src/libexec/httpd/dir-index-bozo.c:1.22 Wed Oct 28 09:20:15 2015 +++ src/libexec/httpd/dir-index-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: dir-index-bozo.c,v 1.22 2015/10/28 09:20:15 shm Exp $ */ +/* $NetBSD: dir-index-bozo.c,v 1.23 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: dir-index-bozo.c,v 1.20 2011/11/18 09:21:15 mrg Exp $ */ @@ -75,7 +75,7 @@ bozo_dir_index(bozo_httpreq_t *request, if (strlen(dirpath) <= strlen(httpd->index_html)) dirpath = "."; else { - file = bozostrdup(httpd, dirpath); + file = bozostrdup(httpd, request, dirpath); file[strlen(file) - strlen(httpd->index_html)] = '\0'; dirpath = file; @@ -114,9 +114,9 @@ bozo_dir_index(bozo_httpreq_t *request, request->hr_file) < 0) bozo_err(httpd, 1, "asprintf"); } else - printname = bozostrdup(httpd, request->hr_file); + printname = bozostrdup(httpd, request, request->hr_file); #else - printname = bozostrdup(httpd, request->hr_file); + printname = bozostrdup(httpd, request, request->hr_file); #endif /* !NO_USER_SUPPORT */ bozo_printf(httpd, Index: src/libexec/httpd/lua-bozo.c diff -u src/libexec/httpd/lua-bozo.c:1.12 src/libexec/httpd/lua-bozo.c:1.13 --- src/libexec/httpd/lua-bozo.c:1.12 Sat Jul 4 22:39:23 2015 +++ src/libexec/httpd/lua-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: lua-bozo.c,v 1.12 2015/07/04 22:39:23 christos Exp $ */ +/* $NetBSD: lua-bozo.c,v 1.13 2015/12/27 10:21:35 mrg Exp $ */ /* * Copyright (c) 2013 Marc Balmer <m...@msys.ch> @@ -123,7 +123,7 @@ lua_register_handler(lua_State *L) handler = bozomalloc(httpd, sizeof(lua_handler_t)); - handler->name = bozostrdup(httpd, lua_tostring(L, 1)); + handler->name = bozostrdup(httpd, NULL, lua_tostring(L, 1)); handler->ref = luaL_ref(L, LUA_REGISTRYINDEX); SIMPLEQ_INSERT_TAIL(&map->handlers, handler, h_next); httpd->process_lua = 1; @@ -184,9 +184,9 @@ bozo_add_lua_map(bozohttpd_t *httpd, con lua_state_map_t *map; map = bozomalloc(httpd, sizeof(lua_state_map_t)); - map->prefix = bozostrdup(httpd, prefix); + map->prefix = bozostrdup(httpd, NULL, prefix); if (*script == '/') - map->script = bozostrdup(httpd, script); + map->script = bozostrdup(httpd, NULL, script); else { char cwd[MAXPATHLEN], *path; @@ -317,20 +317,20 @@ bozo_process_lua(bozo_httpreq_t *request uri = request->hr_oldfile ? request->hr_oldfile : request->hr_file; if (*uri == '/') { - file = bozostrdup(httpd, uri); + file = bozostrdup(httpd, request, uri); if (file == NULL) goto out; - prefix = bozostrdup(httpd, &uri[1]); + prefix = bozostrdup(httpd, request, &uri[1]); } else { if (asprintf(&file, "/%s", uri) < 0) goto out; - prefix = bozostrdup(httpd, uri); + prefix = bozostrdup(httpd, request, uri); } if (prefix == NULL) goto out; if (request->hr_query && request->hr_query[0]) - query = bozostrdup(httpd, request->hr_query); + query = bozostrdup(httpd, request, request->hr_query); p = strchr(prefix, '/'); if (p == NULL) @@ -345,7 +345,7 @@ bozo_process_lua(bozo_httpreq_t *request command = file + 1; if ((s = strchr(command, '/')) != NULL) { - info = bozostrdup(httpd, s); + info = bozostrdup(httpd, request, s); *s = '\0'; } Index: src/libexec/httpd/tilde-luzah-bozo.c diff -u src/libexec/httpd/tilde-luzah-bozo.c:1.12 src/libexec/httpd/tilde-luzah-bozo.c:1.13 --- src/libexec/httpd/tilde-luzah-bozo.c:1.12 Wed Oct 28 09:20:15 2015 +++ src/libexec/httpd/tilde-luzah-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: tilde-luzah-bozo.c,v 1.12 2015/10/28 09:20:15 shm Exp $ */ +/* $NetBSD: tilde-luzah-bozo.c,v 1.13 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: tilde-luzah-bozo.c,v 1.16 2011/11/18 09:21:15 mrg Exp $ */ @@ -77,7 +77,7 @@ bozo_user_transform(bozo_httpreq_t *requ debug((httpd, DEBUG_OBESE, "looking for user %s", user)); pw = getpwnam(user); - request->hr_user = bozostrdup(httpd, user); + request->hr_user = bozostrdup(httpd, request, user); /* fix this up immediately */ if (s) { @@ -113,7 +113,7 @@ bozo_user_transform(bozo_httpreq_t *requ return 0; } if (s == NULL || *s == '\0') { - file = bozostrdup(httpd, "/"); + file = bozostrdup(httpd, request, "/"); } else { file = bozomalloc(httpd, strlen(s) + 2); strcpy(file, "/"); Index: src/libexec/httpd/main.c diff -u src/libexec/httpd/main.c:1.11 src/libexec/httpd/main.c:1.12 --- src/libexec/httpd/main.c:1.11 Sat Dec 12 16:57:53 2015 +++ src/libexec/httpd/main.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.11 2015/12/12 16:57:53 christos Exp $ */ +/* $NetBSD: main.c,v 1.12 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */ /* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */ @@ -128,6 +128,7 @@ main(int argc, char **argv) bozohttpd_t httpd; bozoprefs_t prefs; char *progname; + const char *val; int c; (void) memset(&httpd, 0x0, sizeof(httpd)); @@ -179,15 +180,16 @@ main(int argc, char **argv) #endif /* NO_DYNAMIC_CONTENT */ case 'n': - bozo_set_pref(&prefs, "numeric", "true"); + bozo_set_pref(&httpd, &prefs, "numeric", "true"); break; case 's': - bozo_set_pref(&prefs, "log to stderr", "true"); + bozo_set_pref(&httpd, &prefs, "log to stderr", "true"); break; case 'S': - bozo_set_pref(&prefs, "server software", optarg); + bozo_set_pref(&httpd, &prefs, "server software", + optarg); break; case 'Z': #ifdef NO_SSL_SUPPORT @@ -211,23 +213,23 @@ main(int argc, char **argv) #endif /* NO_SSL_SUPPORT */ case 'U': - bozo_set_pref(&prefs, "username", optarg); + bozo_set_pref(&httpd, &prefs, "username", optarg); break; case 'V': - bozo_set_pref(&prefs, "unknown slash", "true"); + bozo_set_pref(&httpd, &prefs, "unknown slash", "true"); break; case 'v': - bozo_set_pref(&prefs, "virtual base", optarg); + bozo_set_pref(&httpd, &prefs, "virtual base", optarg); break; case 'x': - bozo_set_pref(&prefs, "index.html", optarg); + bozo_set_pref(&httpd, &prefs, "index.html", optarg); break; case 'I': - bozo_set_pref(&prefs, "port number", optarg); + bozo_set_pref(&httpd, &prefs, "port number", optarg); break; #ifdef NO_DAEMON_MODE @@ -245,27 +247,26 @@ main(int argc, char **argv) * background == 2 (aka, -b -b) means to * only process 1 per kid */ - if (bozo_get_pref(&prefs, "background") == NULL) { - bozo_set_pref(&prefs, "background", "1"); - } else { - bozo_set_pref(&prefs, "background", "2"); - } + val = bozo_get_pref(&prefs, "background") == NULL ? + "1" : "2"; + bozo_set_pref(&httpd, &prefs, "background", val); break; case 'e': - bozo_set_pref(&prefs, "dirty environment", "true"); + bozo_set_pref(&httpd, &prefs, "dirty environment", + "true"); break; case 'f': - bozo_set_pref(&prefs, "foreground", "true"); + bozo_set_pref(&httpd, &prefs, "foreground", "true"); break; case 'i': - bozo_set_pref(&prefs, "bind address", optarg); + bozo_set_pref(&httpd, &prefs, "bind address", optarg); break; case 'P': - bozo_set_pref(&prefs, "pid file", optarg); + bozo_set_pref(&httpd, &prefs, "pid file", optarg); break; #endif /* NO_DAEMON_MODE */ @@ -303,7 +304,7 @@ main(int argc, char **argv) break; case 't': - bozo_set_pref(&prefs, "chroot dir", optarg); + bozo_set_pref(&httpd, &prefs, "chroot dir", optarg); break; #ifdef NO_USER_SUPPORT @@ -314,15 +315,16 @@ main(int argc, char **argv) /* NOTREACHED */ #else case 'p': - bozo_set_pref(&prefs, "public_html", optarg); + bozo_set_pref(&httpd, &prefs, "public_html", optarg); break; case 'u': - bozo_set_pref(&prefs, "enable users", "true"); + bozo_set_pref(&httpd, &prefs, "enable users", "true"); break; #ifndef NO_CGIBIN_SUPPORT case 'E': - bozo_set_pref(&prefs, "enable user cgibin", "true"); + bozo_set_pref(&httpd, &prefs, "enable user cgibin", + "true"); break; #else case 'E': @@ -339,11 +341,12 @@ main(int argc, char **argv) /* NOTREACHED */ #else case 'H': - bozo_set_pref(&prefs, "hide dots", "true"); + bozo_set_pref(&httpd, &prefs, "hide dots", "true"); break; case 'X': - bozo_set_pref(&prefs, "directory indexing", "true"); + bozo_set_pref(&httpd, &prefs, "directory indexing", + "true"); break; #endif /* NO_DIRINDEX_SUPPORT */ Index: src/libexec/httpd/ssl-bozo.c diff -u src/libexec/httpd/ssl-bozo.c:1.20 src/libexec/httpd/ssl-bozo.c:1.21 --- src/libexec/httpd/ssl-bozo.c:1.20 Sat Dec 12 18:06:58 2015 +++ src/libexec/httpd/ssl-bozo.c Sun Dec 27 10:21:35 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: ssl-bozo.c,v 1.20 2015/12/12 18:06:58 christos Exp $ */ +/* $NetBSD: ssl-bozo.c,v 1.21 2015/12/27 10:21:35 mrg Exp $ */ /* $eterna: ssl-bozo.c,v 1.15 2011/11/18 09:21:15 mrg Exp $ */ @@ -302,13 +302,13 @@ bozo_ssl_set_opts(bozohttpd_t *httpd, co { sslinfo_t *sslinfo = bozo_get_sslinfo(httpd); - sslinfo->certificate_file = bozo_strdup(httpd, cert); - sslinfo->privatekey_file = bozo_strdup(httpd, priv); + sslinfo->certificate_file = bozostrdup(httpd, NULL, cert); + sslinfo->privatekey_file = bozostrdup(httpd, NULL, priv); debug((httpd, DEBUG_NORMAL, "using cert/priv files: %s & %s", sslinfo->certificate_file, sslinfo->privatekey_file)); if (!httpd->bindport) - httpd->bindport = bozo_strdup(httpd, "https"); + httpd->bindport = bozostrdup(httpd, NULL, "https"); } void @@ -316,7 +316,7 @@ bozo_ssl_set_ciphers(bozohttpd_t *httpd, { sslinfo_t *sslinfo = bozo_get_sslinfo(httpd); - sslinfo->ciphers = bozo_strdup(httpd, ciphers); + sslinfo->ciphers = bozostrdup(httpd, NULL, ciphers); debug((httpd, DEBUG_NORMAL, "using ciphers: %s", sslinfo->ciphers)); } Index: src/libexec/httpd/lua/glue.c diff -u src/libexec/httpd/lua/glue.c:1.1.1.1 src/libexec/httpd/lua/glue.c:1.2 --- src/libexec/httpd/lua/glue.c:1.1.1.1 Mon May 10 03:30:04 2010 +++ src/libexec/httpd/lua/glue.c Sun Dec 27 10:21:35 2015 @@ -92,11 +92,13 @@ l_init_httpd(lua_State *L) static int l_init_prefs(lua_State *L) { + bozohttpd_t *httpd; bozoprefs_t *prefs; prefs = lua_newuserdata(L, sizeof(*prefs)); (void) memset(prefs, 0x0, sizeof(*prefs)); - (void) bozo_init_prefs(prefs); + httpd = lua_touserdata(L, 1); + (void) bozo_init_prefs(httpd, prefs); return 1; }