segmentation fault

Started by Nihongo^, Jul 20, 2023, 08:36 AM

Previous topic - Next topic

habi

Just to confirm, are the IP of the players same?

Nihongo^

Quote from: habi on Jul 23, 2023, 03:09 PMJust to confirm, are the IP of the players same?
Everest is me
but, before 3 players join the server at the same time, and all these players belonged to other locations and then server crashed

i assume that error so i thought i should check it

i joined the server 3 times and then it crashed

habi

It probably was because of variable 'socket' going out of scope.

Check this:
function CheckProxy(ipaddr)
{
 local socket=NewSocket("recv");
 local request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"96ho1j-a57071-8j1317-7vk380");
 getroottable().rawset(ipaddr+"connF",function(){
 socket.Send(request);
 });
 getroottable().rawset(socket,null);
 socket.SetNewConnFunc(ipaddr+"connF");
 socket.Connect("proxycheck.io", 80);
 NewTimer("DestroySocket",5000,1,socket, ipaddr+"connF");
}
function DestroySocket(sock, fname){
if(sock)
{
sock.Delete();
rawdelete(sock);
}
rawdelete(fname);
};

Nihongo^

Quote from: Nihongo^ on Jul 23, 2023, 03:35 PM
Quote from: habi on Jul 23, 2023, 03:09 PMJust to confirm, are the IP of the players same?
Everest is me
but, before 3 players join the server at the same time, and all these players belonged to other locations and then server crashed

i assume that error so i thought i should check it

i joined the server 3 times and then it crashed
hy @habi i am here with my same problem
I thought this matter is solved but its still there. My server crashed when 3/4 players joining the server



function CheckProxy(ipaddr)
{
 local socket=NewSocket("recv");
 local request=format("GET /v2/%s?vpn=1&asn=1&key=%s  HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"3t32l6-477co2-3d0653-2601s0");
 getroottable().rawset(ipaddr+"connF",function(){
 socket.Send(request);
 });
 getroottable().rawset(socket,null);
 socket.SetNewConnFunc(ipaddr+"connF");
 socket.Connect("proxycheck.io", 80);
 NewTimer("DestroySocket",5000,1,socket, ipaddr+"connF");
}
function DestroySocket(sock, fname){
if(sock)
{
 sock.Delete();
 rawdelete(sock);
}
rawdelete(fname);
};
function DestroySocket(sock, fname){
if(sock)sock.Delete();
rawdelete(fname);
};

habi

There is not enough information to find out what has happened? First HttpRequest Module used, then i told to use socket module.

It is your server, so find out what is happening - which line it crashes or when exactly it happens. Try to reproduce it and come with more information. Then i will help you.

Nihongo^

#35
Quote from: habi on Jul 20, 2023, 11:39 AMWorking fine for me on WSL Ubuntu
I use httprequests04rel64[dot]so from here (0.2.1)
scripts/httptest.nut
request <- ::SqHTTP.GetRequest();
request.setURL("https://proxycheck.io/v2/79.137.85.208?vpn=1&asn=1")
request.setTag("James_Bond");
function HTTP_OnResponse(tag, url, statusCode, response)
{
   // Check if the request was successful
   if (statusCode == 200)
   {
local findProxy = response.find("proxy\": \"yes");

if (findProxy != null)
{
print("-------PROXY DETECTED-------");
print("Name: "+tag);
print("----------------------------");
//To get the player instance
local player = FindPlayer(tag);
if( player && player.Name == tag )
{
MessagePlayer("You are about to be k**ck*d", player);
}else
{
//player /q before the response arrived!
}
} else
{
print(tag+ " is not using a proxy.");
}

}else {
    // Handle HTTP request error
    print("Proxy check request failed with status code " + statusCode);
   } 

}
request.sendGet();

The screenshot is not of Windows but of Linux(Ubuntu.)
There is a tag function for http request. You simply set it as player's name. Then using the tag, find the player.

I recently discovered that the issue causing a "segmentation fault" is related to the Discord plugins and the httprequest04rel64 plugins. When I remove the Discord plugins from my server, the httprequest works perfectly and displays the desired result. However, if I prioritize loading the Discord plugins first, it leads to a segmentation fault during the server loading process. My suspicion is that OpenSSL operates exclusively for either Discord or httprequest at a given time.

habi

Maybe the discord module is faulty. I don't think OpenSSL has anything to do with it.
I see from your console, you are using a modified version of discord plugin, is the source code of it available?

Nihongo^

#37
Quote from: habi on Aug 13, 2023, 02:41 PMis the source code of it available?

Thank you for the reply,
afaik it one of my friends who gave me this plugin because the current one is not working/not updated
i think it was @KAKAN

P.S maybe it can help i am not sure he shared this link with me i didn't get what is it
https://github.com/kakan-gamerelated/sleepydiscord-squirrel

habi

I went through the code, there was no  mistake like i thought.

Since you said everything is working good on windows, then this might be a bug with vcmp modules sharing same function names. Both httprequests04 and discord04 use sqrat namespaces and it might be a problem with that. I don't know, i have reported this instance [url here.

When i come back, we will write a new code using sockets again which will not crash. You also have to make sure all your functions are good and no duplicate events exist.

...

habi

#39
I was yesterday making a curl module, but not completed. But i believe in socket plugin, so today made this:
function CheckProxy(ipaddr)
{
 local socket=NewSocket("recv");
//Your request
 local request=format("GET /v2/%s?vpn=1&asn=1&key=%s HTTP/1.1\r\nHost: proxycheck.io\r\nAccept: */*\r\n\r\n", ipaddr,"96ho1j-a57071-8j1317-7vk380");

//Making individual slot name formatted so that they are different for any two different players.
local funcname = format("%s_%s_func", ipaddr, GetTickCount() );
local sockname = format("%s_%s_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%s_rqst", ipaddr, GetTickCount() );

//NewConnFunc
local func= function(){
if(rawin(sockname) && rawin(requestname))
{
local _socket = rawget(sockname);
local _request = rawget(requestname);
_socket.Send(_request);
}
}
//LostConnFunc and its name
local lostfunc= function(){
if(rawin(sockname))
 rawdelete(sockname);
if(rawin(requestname))
 rawdelete(requestname);
}
local lostname= format("%s_%s_lost", ipaddr, GetTickCount() );

//Set these pairs in roottable
rawset(funcname, func);
rawset(sockname, socket);
rawset(requestname, request);
rawset(lostname, lostfunc);

socket.SetNewConnFunc(funcname);
socket.SetLostConnFunc(lostname);

socket.Connect("proxycheck.io", 80);

NewTimer("DestroySocket",10000,1,funcname, sockname, requestname, lostname);//After 10 seconds
}

function DestroySocket(fname, sname, reqname, lname)
{
if(rawin(sname))
{
 rawget(sname).Delete(); //Delete socket
 rawdelete(sname); //Delete slot
}
if(rawin(fname))
 rawdelete(fname);
if(rawin(reqname))
 rawdelete(reqname);
if(rawin(lname))
 rawdelete(lname);
}
//Need not delete timer in lost connection function, because timer has 'if' inside it.
* recv is same and i hope you have not bugs inside it.
*Unload httprequests04 from your system ( assuming it is clashing with discord04)
*code is not tested

Nihongo^

#40
I was yesterday making a curl module
Best of luck with your endeavors! also tell us what's the benefits of it ?

I've noticed your diligent work for this community, actively breathing life into it. I genuinely appreciate your dedicated efforts.

In regards to the code, I will review it shortly.

Nihongo^

Hy habi sorry it has some bugs at line 8



and here's the line 8

local funcname = format("%s_%s_func", ipaddr, GetTickCount() );

habi

#42
Replace %s by %d second time:
local funcname = format("%s_%d_func", ipaddr, GetTickCount() );
local sockname = format("%s_%d_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%d_rqst", ipaddr, GetTickCount() );

Nihongo^

Quote from: habi on Aug 15, 2023, 05:27 PMReplace %s by %d second time:
local funcname = format("%s_%d_func", ipaddr, GetTickCount() );
local sockname = format("%s_%d_sock", ipaddr, GetTickCount() );
local requestname = format("%s_%d_rqst", ipaddr, GetTickCount() );
Thank you, it works. For testing purposes, I repeated the same action that previously led to crashes (joining every time). As a result, it's now causing bugs at line 291 in the JSONParser.nut and then server off (segmentation fault)



Line 291
  throw "JSON Syntax Error near `" + near + "`";
Full code

/**
 * JSON Parser
 *
 * @author Mikhail Yurasov <[email protected]>
 * @package JSONParser
 * @version 1.0.1
 */

/**
 * JSON Parser
 * @package JSONParser
 */
class JSONParser {

  // should be the same for all components within JSONParser package
  static version = "1.0.1";

  /**
  * Parse JSON string into data structure
  *
  * @param {string} str
  * @param {function({string} value[, "number"|"string"])|null} converter
  * @return {*}
  */
  function parse(str, converter = null) {

    local state;
    local stack = []
    local container;
    local key;
    local value;

    // actions for string tokens
    local string = {
      go = function () {
        state = "ok";
      },
      firstokey = function () {
        key = value;
        state = "colon";
      },
      okey = function () {
        key = value;
        state = "colon";
      },
      ovalue = function () {
        value = this._convert(value, "string", converter);
        state = "ocomma";
      }.bindenv(this),
      firstavalue = function () {
        value = this._convert(value, "string", converter);
        state = "acomma";
      }.bindenv(this),
      avalue = function () {
        value = this._convert(value, "string", converter);
        state = "acomma";
      }.bindenv(this)
    };

    // the actions for number tokens
    local number = {
      go = function () {
        state = "ok";
      },
      ovalue = function () {
        value = this._convert(value, "number", converter);
        state = "ocomma";
      }.bindenv(this),
      firstavalue = function () {
        value = this._convert(value, "number", converter);
        state = "acomma";
      }.bindenv(this),
      avalue = function () {
        value = this._convert(value, "number", converter);
        state = "acomma";
      }.bindenv(this)
    };

    // action table
    // describes where the state machine will go from each given state
    local action = {

      "{": {
        go = function () {
          stack.push({state = "ok"});
          container = {};
          state = "firstokey";
        },
        ovalue = function () {
          stack.push({container = container, state = "ocomma", key = key});
          container = {};
          state = "firstokey";
        },
        firstavalue = function () {
          stack.push({container = container, state = "acomma"});
          container = {};
          state = "firstokey";
        },
        avalue = function () {
          stack.push({container = container, state = "acomma"});
          container = {};
          state = "firstokey";
        }
      },

      "}" : {
        firstokey = function () {
          local pop = stack.pop();
          value = container;
          container = ("container" in pop) ? pop.container : null;
          key = ("key" in pop) ? pop.key : null;
          state = pop.state;
        },
        ocomma = function () {
          local pop = stack.pop();
          container[key] <- value;
          value = container;
          container = ("container" in pop) ? pop.container : null;
          key = ("key" in pop) ? pop.key : null;
          state = pop.state;
        }
      },

      "[" : {
        go = function () {
          stack.push({state = "ok"});
          container = [];
          state = "firstavalue";
        },
        ovalue = function () {
          stack.push({container = container, state = "ocomma", key = key});
          container = [];
          state = "firstavalue";
        },
        firstavalue = function () {
          stack.push({container = container, state = "acomma"});
          container = [];
          state = "firstavalue";
        },
        avalue = function () {
          stack.push({container = container, state = "acomma"});
          container = [];
          state = "firstavalue";
        }
      },

      "]" : {
        firstavalue = function () {
          local pop = stack.pop();
          value = container;
          container = ("container" in pop) ? pop.container : null;
          key = ("key" in pop) ? pop.key : null;
          state = pop.state;
        },
        acomma = function () {
          local pop = stack.pop();
          container.push(value);
          value = container;
          container = ("container" in pop) ? pop.container : null;
          key = ("key" in pop) ? pop.key : null;
          state = pop.state;
        }
      },

      ":" : {
        colon = function () {
          // Check if the key already exists
          // NOTE previous code used 'if (key in container)...'
          //      but this finds table ('container') member methods too
          local err = false;
          foreach (akey, avalue in container) {
            if (akey == key) err = true;
            break
          }
          if (err) throw "Duplicate key \"" + key + "\"";
          state = "ovalue";
        }
      },

      "," : {
        ocomma = function () {
          container[key] <- value;
          state = "okey";
        },
        acomma = function () {
          container.push(value);
          state = "avalue";
        }
      },

      "true" : {
        go = function () {
          value = true;
          state = "ok";
        },
        ovalue = function () {
          value = true;
          state = "ocomma";
        },
        firstavalue = function () {
          value = true;
          state = "acomma";
        },
        avalue = function () {
          value = true;
          state = "acomma";
        }
      },

      "false" : {
        go = function () {
          value = false;
          state = "ok";
        },
        ovalue = function () {
          value = false;
          state = "ocomma";
        },
        firstavalue = function () {
          value = false;
          state = "acomma";
        },
        avalue = function () {
          value = false;
          state = "acomma";
        }
      },

      "null" : {
        go = function () {
          value = null;
          state = "ok";
        },
        ovalue = function () {
          value = null;
          state = "ocomma";
        },
        firstavalue = function () {
          value = null;
          state = "acomma";
        },
        avalue = function () {
          value = null;
          state = "acomma";
        }
      }
    };

    //

    state = "go";
    stack = [];

    // current tokenizeing position
    local start = 0;

    try {

      local
        result,
        token,
        tokenizer = _JSONTokenizer();

      while (token = tokenizer.nextToken(str, start)) {

        if ("ptfn" == token.type) {
          // punctuation/true/false/null
          action[token.value][state]();
        } else if ("number" == token.type) {
          // number
          value = token.value;
          number[state]();
        } else if ("string" == token.type) {
          // string
          value = tokenizer.unescape(token.value);
          string[state]();
        }

        start += token.length;
      }

    } catch (e) {
      state = e;
    }

    // check is the final state is not ok
    // or if there is somethign left in the str
    if (state != "ok" || regexp("[^\\s]").capture(str, start)) {
      local min = @(a, b) a < b ? a : b;
      local near = str.slice(start, min(str.len(), start + 10));
        throw "JSON Syntax Error near `" + near + "`"; <---- 291
    }

    return value;
  }


habi

i have no idea why this is caused. To investigate, we need the reply string from proxycheck.io which when passed to JsonParser is throwing the error.
Did you bypassed their daily limit or something so something different is send back as reply?
The inference is the string may not be in the format preferred by JsonParser.
Try to print the string like this
foreach(s in str)stdout.writen(s, 'c'); in line 190.