From d82179191d60b15e23619e369f5804cf9def2dea Mon Sep 17 00:00:00 2001 From: Mikhail Novosyolov Date: Wed, 15 Jun 2022 17:40:56 +0300 Subject: [PATCH] Disallow to define only width and height of the client screen --- webserver/doskast-trigger-connect.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/webserver/doskast-trigger-connect.c b/webserver/doskast-trigger-connect.c index bcc5a09..14d8061 100644 --- a/webserver/doskast-trigger-connect.c +++ b/webserver/doskast-trigger-connect.c @@ -86,6 +86,8 @@ int main(){ int rc = 0; int http_code = HTTP_ERROR; + // text of errors which must be seen by people + char *error_msg; if (access(DIR, W_OK) != 0) { fprintf(stderr, "Directory %s does not exist or is not writable\n", DIR); goto out; @@ -115,6 +117,16 @@ main(){ } char *cgi_width = cgiGetValue(cgi, "width"); char *cgi_height = cgiGetValue(cgi, "height"); + int bal = 0; + if ( (cgi_width != NULL) && (_verify_geometry(cgi_width) == 0) ) + bal++; + if ( (cgi_height != NULL) && (_verify_geometry(cgi_height) == 0) ) + bal++; + if (bal == 1) { + error_msg = "Define both width and height"; + http_code = HTTP_BAD_REQUEST; + goto fcgi_out; + } char *hex; int max_try = 10; for (int i = 1; i <= max_try; i++) { @@ -139,10 +151,10 @@ main(){ goto fcgi_out; } fprintf(d, "ip=%s\n", ip); - if ( (cgi_width != NULL) && (_verify_geometry(cgi_width) == 0) ) + if (bal == 2) { fprintf(d, "width=%s\n", cgi_width); - if ( (cgi_height != NULL) && (_verify_geometry(cgi_height) == 0) ) fprintf(d, "height=%s\n", cgi_height); + } rc = fclose(d); if (rc != 0) { fprintf(stderr, "Error closing file %s/%s\n", DIR, hex); @@ -159,6 +171,8 @@ fcgi_out: printf("%s\r\n", "OK"); rc = 0; } else { + if (error_msg) + printf("ERROR: %s\r\n", error_msg); rc = 1; } }