Forum

Bugfixes and missing CGI variables

Stephen R. van den Berg
21 February 2011, 15:39
The following patches are a followup to the last batch I sent in.

From c82125ef13b0f5fc9d1075a89510a6802df8d1f4 Mon Sep 17 00:00:00 2001
From: Stephen R. van den Berg <srb@cuci.nl>
Date: Sat, 19 Feb 2011 23:56:56 +0100
Subject: Reverse error reporting logic, regression bug.

---
libfs.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libfs.c b/libfs.c
index f1967a7..a786335 100644
--- a/libfs.c
+++ b/libfs.c
@@ -252,7 +252,7 @@ void touch_logfile(char *dir, char *file, mode_t mode, uid_t uid, gid_t gid) {
oldeuid = geteuid();
oldegid = getegid();
setegid(gid);seteuid(uid);
- if ((fd = open(logfile, O_CREAT, mode)) != -1) {
+ if ((fd = open(logfile, O_CREAT, mode)) < 0) {
fprintf(stderr, "Warning: couldn't create logfile %s\n", logfile);
} else {
close(fd);
--
1.7.1


From 16be2e1e7ebed05ea27c17346e24737832dc26ac Mon Sep 17 00:00:00 2001
From: Stephen R. van den Berg <srb@cuci.nl>
Date: Mon, 21 Feb 2011 02:33:03 +0100
Subject: DOCUMENT_ROOT should end in a trailing slash.

---
serverconfig.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/serverconfig.c b/serverconfig.c
index 8972f2a..a4fb94c 100644
--- a/serverconfig.c
+++ b/serverconfig.c
@@ -1286,8 +1286,13 @@ static bool host_setting(char *key, char *value, t_host *host) {
}
} else if (strcmp(key, "websiteroot") == 0) {
if (valid_directory(value)) {
- if ((host->website_root = strdup(value)) != NULL) {
- host->website_root_len = strlen(host->website_root);
+ char *s;
+ int len;
+ if (s = malloc((len=strlen(value))+2)) {
+ host->website_root = s;
+ strcpy(s, value);
+ s[len]='/';s[len+1]='\0';
+ host->website_root_len = len;
return true;
}
}
--
1.7.1


From a03e61f0b8bdcb3134802fed732f11e04d1e2caa Mon Sep 17 00:00:00 2001
From: Stephen R. van den Berg <srb@cuci.nl>
Date: Mon, 21 Feb 2011 02:46:52 +0100
Subject: PATH_TRANSLATED added.

---
envir.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/envir.c b/envir.c
index b81f503..dcf86e3 100644
--- a/envir.c
+++ b/envir.c
@@ -243,7 +243,18 @@ void set_environment(t_session *session, t_fcgi_buffer *fcgi_buffer) {
#endif

if (session->path_info != NULL) {
+ char *path_translated;
+ int len = session->host->website_root_len;
add_to_environment(fcgi_buffer, "PATH_INFO", session->path_info);
+ path_translated = malloc(len + strlen(session->path_info) + 1);
+ if(path_translated) {
+ memcpy(path_translated, session->host->website_root,
+ len);
+ strcpy(path_translated + len, session->path_info);
+ add_to_environment(fcgi_buffer, "PATH_TRANSLATED",
+ path_translated);
+ free(path_translated);
+ }
}

snprintf(value, 9, "%d", session->return_code);
--
1.7.1
Hugo Leisink
22 February 2011, 23:38
Can you give a brief summary of what the patch changes and why?
Stephen R. van den Berg
24 February 2011, 11:14
I thought I did (the Subject lines), but perhaps it's too brief.
Here goes, in chronological order:
- Fix a regression bug in my previous patch(es), I accidentally showed spurious error messages if the logfile already existed.
- Apache sends DOCUMENT_ROOT variables to the CGI scripts which contain the trailing slash; this patch makes hiawatha compatible with that behaviour.
- PATH_TRANSLATED is sent by Apache to CGI programs, this adds the variable to the list provided by Hiawatha as well.
Stephen R. van den Berg
24 February 2011, 11:30
Incidentally, I notice that my name gets truncated on your forum. Could you widen the allocated string by perhaps 3 characters? :-)
This topic has been closed.