Search code examples
httprequestg-wanserver-configuration

G-WAN - How to return Status Code: 200 OK if request URL = 541+ characters?


I'm using G-WAN Web App. Server v7.12.6.

How to return valid Status Code: 200 OK if request URL has a total of 541+ characters including the 25 parameters?

ajaxGet(URL, method) where method is GET or PUT (same result)

Request URL:

http://myWebsite.ca:xx/?createCompany.c&legalname=mycomp&dba=mycomp%20dba&www=www.myWebsite... 

createCompany.c

#pragma link "pq"
#include <stdlib.h>
#include <string.h>
#include "/usr/include/postgresql/libpq-fe.h"
#include "gwan.h"
//----------------------------------------------------------------------------

int main(int argc, char *argv[]) {

  u64 start = getus();
  PGconn *conn;
  PGresult *res;
  char DBrequestString [1000] = "";

  char *legal_name = 0, *dba = 0, *www = 0; //...+ 22 more

  xbuf_t *reply = get_reply(argv);

  get_arg("legalname=", &legal_name, argc, argv);
  get_arg("dba=", &dba, argc, argv);
  get_arg("www=", &www, argc, argv);
  //...+ 22 more

  char requestString[1000] = "SELECT create_company('%s','%s','%s', ... + 22 more);";
  sprintf(DBrequestString, requestString,legal_name, dba, www, ... + 22 more);

  conn = PQconnectdb("host=x port=x dbname=x user=x password=x");

  if (PQstatus(conn) != CONNECTION_OK){
    fprintf(stderr, "Connection to database failed: %s",PQerrorMessage(conn));
    PQfinish(conn);
    xbuf_cat(reply, "{\"message\":\"Connection to database failed !\"}");//message Json format
    return 200;
  }
  res = PQexec(conn, DBrequestString);

  printf(" --> %s\n",PQgetvalue(res, 0, 0));
  xbuf_cat(reply, PQgetvalue(res, 0, 0));//return one line Json format

  PQclear(res);
  PQfinish(conn);
  printf("TEMPS D'EXECUTION: %.2Fms\n\n",(getus() - start)/1000.0);
  return 200; //return OK
}

Solution

  • Good question - I don't have access to the source code righ tnow but looking at the G-WAN API on the website made me think that either READ_XBUF or MAX_ENTITY_SIZE might help.

    Typically, READ_XBUF would be used in a G-WAN HANDLER to augment (if needed) the connection buffer while MAX_ENTITY_SIZE is a one-time setting that can be changed at any time (and even before the server starts, thanks to the init.c script).

    I think that just enlarging the MAX_ENTITY_SIZE value (which purpose is to prevent lage-entity DoS attacks) would do the job because it is most likely that G-WAN automatically enlarges the READ_XBUF on a per request basis when reading from the client.