X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/agedu/blobdiff_plain/cc7db507cc53258e23c148c690c9e450214f93ac..14601b5d4222f2bee568e03eddf2f949b2a9d126:/httpd.c diff --git a/httpd.c b/httpd.c index bbe82ab..2437cdd 100644 --- a/httpd.c +++ b/httpd.c @@ -269,16 +269,22 @@ char *got_data(struct connctx *ctx, char *data, int length, "This is a restricted-access set of pages."); } } else { + char *q; p = ctx->url; p += strspn(p, "/?"); - index = strtoul(p, NULL, 10); - document = html_query(ctx->t, index, cfg); - if (document) { - ret = http_success("text/html", 1, document); - sfree(document); - } else { + index = strtoul(p, &q, 10); + if (*q) { ret = http_error("404", "Not Found", NULL, - "Pathname index out of range."); + "This is not a valid pathname index."); + } else { + document = html_query(ctx->t, index, cfg); + if (document) { + ret = http_success("text/html", 1, document); + sfree(document); + } else { + ret = http_error("404", "Not Found", NULL, + "Pathname index out of range."); + } } } return ret; @@ -362,9 +368,11 @@ int check_owning_uid(int fd, int flip) while (fgets(linebuf, sizeof(linebuf), fp)) { if (strlen(linebuf) >= 75 && !strncmp(linebuf+6, matchbuf, strlen(matchbuf))) { + fclose(fp); return atoi(linebuf + 75); } } + fclose(fp); } return -1;