From 0779ca5060c3108d6df5feb871840024a000b9f7 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Wed, 23 Mar 2022 19:08:52 +0000 Subject: [PATCH] Fix read(0) bug FCGI_stdio does not map stdin's socket, it only wraps the stdio FILE* FossilOrigin-Name: 0e068eda84d8938d2c47eca010cf828c661f76de29547bb6ce46855f09247bb4 --- src/account.c | 2 +- src/base_page.c | 2 ++ src/base_page.h | 2 +- src/error.c | 2 +- src/lists.c | 2 +- src/login.c | 5 +++-- src/main.c | 2 +- src/notifications.c | 2 +- src/page_config.c | 2 +- src/query.c | 20 ++++++++------------ src/query.h | 1 + src/status.c | 2 +- src/test.c | 2 +- src/timeline.c | 4 ++-- static/index.html | 4 +++- 15 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/account.c b/src/account.c index 482af4a..896df44 100644 --- a/src/account.c +++ b/src/account.c @@ -95,7 +95,7 @@ void content_account(mastodont_t* api, char** data, size_t size) struct base_page b = { .locale = L10N_EN_US, .content = account_page, - .sidebar_right = NULL + .sidebar_left = NULL }; /* Output */ diff --git a/src/base_page.c b/src/base_page.c index 804d63a..4d1555a 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -93,6 +93,8 @@ void render_base_page(struct base_page* page, mastodont_t* api) L10N[locale][L10N_DIRECT], config_url_prefix, L10N[locale][L10N_CONFIG], + page->sidebar_left ? + page->sidebar_left : "", page->content, sidebar_str ? sidebar_str : "

Not logged in

"); diff --git a/src/base_page.h b/src/base_page.h index daf0fd0..351e19b 100644 --- a/src/base_page.h +++ b/src/base_page.h @@ -26,7 +26,7 @@ struct base_page { enum l10n_locale locale; char* content; - char* sidebar_right; + char* sidebar_left; }; void render_base_page(struct base_page* page, mastodont_t* api); diff --git a/src/error.c b/src/error.c index 7ea3259..e800b24 100644 --- a/src/error.c +++ b/src/error.c @@ -44,7 +44,7 @@ void content_not_found(mastodont_t* api, char* path) struct base_page b = { .locale = L10N_EN_US, .content = page, - .sidebar_right = NULL + .sidebar_left = NULL }; render_base_page(&b, api); diff --git a/src/lists.c b/src/lists.c index 6ea20b5..d99926d 100644 --- a/src/lists.c +++ b/src/lists.c @@ -85,7 +85,7 @@ void content_lists(mastodont_t* api, char** data, size_t size) struct base_page b = { .locale = L10N_EN_US, .content = lists_page, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/src/login.c b/src/login.c index 9669ffa..3304c42 100644 --- a/src/login.c +++ b/src/login.c @@ -37,6 +37,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size) char* error = NULL; char* page; + printf("%s: %s\r\n", post.username ? post.username: "none", post.password ? post.password : "none"); if (post.username && post.password) { // Getting the client id/secret @@ -71,7 +72,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size) printf("Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token.access_token); printf("Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n"); // if config_url_prefix is empty, make it root - printf("Location: %s/\r\n", + printf("Location: %s\r\n\r\nRedirecting...", config_url_prefix[0] == '\0' ? "/" : config_url_prefix); return; @@ -90,7 +91,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size) struct base_page b = { .locale = L10N_EN_US, .content = page, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/src/main.c b/src/main.c index b616d0b..c9d8dec 100644 --- a/src/main.c +++ b/src/main.c @@ -43,7 +43,7 @@ int main(void) unsigned run_count = 1; // API - for (;FCGI_Accept() >= 0; ++run_count) + while (FCGI_Accept() >= 0) { mastodont_t api; api.url = config_instance_url; diff --git a/src/notifications.c b/src/notifications.c index cd380ac..286076a 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -91,7 +91,7 @@ void content_notifications(mastodont_t* api, char** data, size_t data_size) struct base_page b = { .locale = L10N_EN_US, .content = data_notifications_page_html, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/src/page_config.c b/src/page_config.c index 5610746..35d1f69 100644 --- a/src/page_config.c +++ b/src/page_config.c @@ -43,7 +43,7 @@ void content_config(mastodont_t* api, char** data, size_t size) struct base_page b = { .locale = L10N_EN_US, .content = data_config_html, - .sidebar_right = NULL + .sidebar_left = NULL }; render_base_page(&b, api); diff --git a/src/query.c b/src/query.c index 78e4b8c..34cce4c 100644 --- a/src/query.c +++ b/src/query.c @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -#include -#include +#include #include +#include #include #include "query.h" #include "key.h" @@ -28,7 +28,6 @@ struct query_values post = { 0 }; char* read_post_data() { struct http_query_info info; - char* post_env = getenv("POST"); char* request_method = getenv("REQUEST_METHOD"); char* post_query = NULL, *p_query_read; @@ -44,22 +43,19 @@ char* read_post_data() }; // END Query references - if ((request_method && (strcmp("POST", request_method) == 0)) || post_env) + if (request_method && strcmp("POST", request_method) == 0) { - int content_length = post_env ? strlen(post_env) : atoi(getenv("CONTENT_LENGTH")); + int content_length = atoi(getenv("CONTENT_LENGTH")); post_query = malloc(content_length + 1); if (!post_query) { perror("malloc"); return NULL; } - if (post_env) - strcpy(post_query, post_env); - else { - // Read in data - read(STDIN_FILENO, post_query, content_length); - post_query[content_length] = '\0'; - } + + // fread should be a macro to FCGI_fread, which is set by FCGI_Accept in previous definitions + size_t len = fread(post_query, 1, content_length, stdin); + post_query[content_length] = '\0'; // For shifting through p_query_read = post_query; diff --git a/src/query.h b/src/query.h index 16c1950..074faef 100644 --- a/src/query.h +++ b/src/query.h @@ -18,6 +18,7 @@ #ifndef QUERY_H #define QUERY_H +#include #include struct http_query_info diff --git a/src/status.c b/src/status.c index 34a219c..5b4086c 100644 --- a/src/status.c +++ b/src/status.c @@ -217,7 +217,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl struct base_page b = { .locale = L10N_EN_US, .content = output, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/src/test.c b/src/test.c index 48432a5..1388541 100644 --- a/src/test.c +++ b/src/test.c @@ -70,7 +70,7 @@ void content_test(mastodont_t* api, char** data, size_t data_size) struct base_page b = { .locale = L10N_EN_US, .content = page, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/src/timeline.c b/src/timeline.c index e6cd7b8..fac32c1 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -65,7 +65,7 @@ void tl_public(mastodont_t* api, int local) struct base_page b = { .locale = L10N_EN_US, .content = output, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output @@ -116,7 +116,7 @@ void tl_list(mastodont_t* api, char* list_id) struct base_page b = { .locale = L10N_EN_US, .content = output, - .sidebar_right = NULL + .sidebar_left = NULL }; // Output diff --git a/static/index.html b/static/index.html index 605f293..c404aff 100644 --- a/static/index.html +++ b/static/index.html @@ -31,8 +31,10 @@
  • %s
  • %s
  • %s
  • -
  • %s
  • %s
  • +
  • %s
  • +
  • %s
  • + %s