{"action":"opened","issue":{"url":"https://api.github.com/repos/keplerproject/luasql/issues/55","repository_url":"https://api.github.com/repos/keplerproject/luasql","labels_url":"https://api.github.com/repos/keplerproject/luasql/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/keplerproject/luasql/issues/55/comments","events_url":"https://api.github.com/repos/keplerproject/luasql/issues/55/events","html_url":"https://github.com/keplerproject/luasql/issues/55","id":168316709,"number":55,"title":"luasql.postgres: SIGSEGV and crash if conn:escape(string) and returned string >8199 bytes","user":{"login":"shripchenko","id":1335941,"avatar_url":"https://avatars.githubusercontent.com/u/1335941?v=3","gravatar_id":"","url":"https://api.github.com/users/shripchenko","html_url":"https://github.com/shripchenko","followers_url":"https://api.github.com/users/shripchenko/followers","following_url":"https://api.github.com/users/shripchenko/following{/other_user}","gists_url":"https://api.github.com/users/shripchenko/gists{/gist_id}","starred_url":"https://api.github.com/users/shripchenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shripchenko/subscriptions","organizations_url":"https://api.github.com/users/shripchenko/orgs","repos_url":"https://api.github.com/users/shripchenko/repos","events_url":"https://api.github.com/users/shripchenko/events{/privacy}","received_events_url":"https://api.github.com/users/shripchenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-29T12:44:18Z","updated_at":"2016-07-29T12:44:18Z","closed_at":null,"body":"This sample script\r\n```lua\r\nlocal luasql = require \"luasql.postgres\"\r\nlocal env = assert(luasql.postgres())\r\nlocal conn = assert(env:connect(<your conn string here>))\r\n\r\nfor i=4080,5000,1 do\r\n        local s1 = string.rep(\"'\", i)\r\n        local s2 = conn:escape(s1)\r\n        print(string.format(\"s1=%i, s2=%i\", string.len(s1), string.len(s2)))\r\nend\r\n```\r\nwill be failed after `s1=4099, s2=8198` iteration and generate either SIGSEGV, or random error like:\r\n```\r\ns1=4099, s2=8198\r\nSegmentation fault\r\n```\r\n```\r\ns1=4099, s2=8198\r\nlua: bad argument #1 to 'string.len' (string expected, got function)\r\nstack traceback:\r\n        [C]: in function 'string.len'\r\n        [C]: in function 'len'\r\n        ./bla2.lua:8: in main chunk\r\n        [C]: in ?\r\n```\r\n\r\nsome insights after brief looking to code:\r\n`luaL_Buffer b;` - default buffer size of 8192\r\n`char *to = luaL_buffinitsize (L, &b, 2*len+1);` - not checking actual returned buffer size\r\n`luaL_buffinit (L, &b);` - init buffer with defaiut size of 8192 regardles of `len`\r\n`len = PQescapeStringConn (conn->pg_conn, to, from, len, &error);` - `len` parameter does not take into account an actual buffer size"}}
{"actor":{"display_login":"shripchenko"}}