summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-04-24 22:29:44 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-04-24 22:29:44 +0300
commitb2156c559a91ad4eed241d6a624a8ecfac576174 (patch)
tree2984347856fb6a77a3cb86beab9a168353a0be46
parent56edbac842e7a8cd256bf099715265a793c92d55 (diff)
downloadfileserv-b2156c559a91ad4eed241d6a624a8ecfac576174.tar.gz
fileserv-b2156c559a91ad4eed241d6a624a8ecfac576174.tar.bz2
Minor fix
* fileserv.c (http_log): Avoid dereferencing NULL pointers.
-rw-r--r--src/fileserv.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/fileserv.c b/src/fileserv.c
index 58262c3..568ba37 100644
--- a/src/fileserv.c
+++ b/src/fileserv.c
@@ -506,12 +506,18 @@ get_file_resp(struct MHD_Connection *conn, char const *url, FILE_RESP *resp)
506 fstat(resp->fd, &resp->st); 506 fstat(resp->fd, &resp->st);
507 resp->type = get_file_type(resp->file_name); 507 resp->type = get_file_type(resp->file_name);
508 508
509 return MHD_HTTP_OK; 509 return MHD_HTTP_OK;
510} 510}
511 511
512static inline char const *
513safestr(char const *s)
514{
515 return s ? s : "-";
516}
517
512void 518void
513http_log(struct MHD_Connection *connection, 519http_log(struct MHD_Connection *connection,
514 char const *method, char const *url, 520 char const *method, char const *url,
515 int status, struct stat const *st) 521 int status, struct stat const *st)
516{ 522{
517 char *ipstr; 523 char *ipstr;
@@ -534,15 +540,14 @@ http_log(struct MHD_Connection *connection,
534 540
535 t = time(NULL); 541 t = time(NULL);
536 tm = localtime(&t); 542 tm = localtime(&t);
537 strftime(tbuf, sizeof(tbuf), "[%d/%b/%Y:%H:%M:%S %z]", tm); 543 strftime(tbuf, sizeof(tbuf), "[%d/%b/%Y:%H:%M:%S %z]", tm);
538 544
539 info("%s %s - - %s \"%s %s\" %3d %lu \"%s\" \"%s\"", 545 info("%s %s - - %s \"%s %s\" %3d %lu \"%s\" \"%s\"",
540 host, ipstr, tbuf, method, url, status, st ? st->st_size : 0, 546 safestr(host), ipstr, tbuf, method, url, status,
541 referer ? referer : "", 547 st ? st->st_size : 0, safestr(referer), safestr(user_agent));
542 user_agent ? user_agent : "");
543 free(ipstr); 548 free(ipstr);
544} 549}
545 550
546static int 551static int
547http_redirect(struct MHD_Connection *connection, 552http_redirect(struct MHD_Connection *connection,
548 char const *method, char const *url, 553 char const *method, char const *url,

Return to:

Send suggestions and report system problems to the System administrator.