Title: Crash due to ConVar overlap and release. #421 · Issue #430 · Source-Python-Dev-Team/Source.Python · GitHub
Open Graph Title: Crash due to ConVar overlap and release. #421 · Issue #430 · Source-Python-Dev-Team/Source.Python
X Title: Crash due to ConVar overlap and release. #421 · Issue #430 · Source-Python-Dev-Team/Source.Python
Description: This is an issue derived from #421 and introduced by 02e3490. There is a long discussion going on in #421, and I've created an issue for the record. The main issue is due to Source.Python releasing the ConVar object created by ConVar(str...
Open Graph Description: This is an issue derived from #421 and introduced by 02e3490. There is a long discussion going on in #421, and I've created an issue for the record. The main issue is due to Source.Python releasing...
X Description: This is an issue derived from #421 and introduced by 02e3490. There is a long discussion going on in #421, and I've created an issue for the record. The main issue is due to Source.Python relea...
Opengraph URL: https://github.com/Source-Python-Dev-Team/Source.Python/issues/430
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash due to ConVar overlap and release. #421","articleBody":"This is an issue derived from #421 and introduced by 02e34907fc86036228d132526edcd8f847a0650a. There is a long discussion going on in #421, and I've created an issue for the record.\r\n\r\nThe main issue is due to Source.Python releasing the ConVar object created by [ConVar(str)](https://github.com/Source-Python-Dev-Team/Source.Python/blob/02e34907fc86036228d132526edcd8f847a0650a/src/core/modules/cvars/cvars_wrap.cpp#L207) when the plugin is unloaded. This will cause other Source.Python/SourceMod plugins to crash if they hold the same ConVar object.\r\n\r\nCode:\r\n\r\nPlugin1 (test1)\r\n```python\r\nfrom cvars import ConVar\r\ntest_convar = ConVar(\"test_convar\", \"1\", \"Test Convar(test1).\")\r\n```\r\n\r\nPlugin2 (test2) Or a SourceMod plugin with equivalent functionality.\r\n```python\r\nfrom commands.server import ServerCommand\r\nfrom cvars import ConVar\r\ntest_convar = ConVar(\"test_convar\", \"2\", \"Test Convar(test2).\")\r\n\r\n@ServerCommand(\"set_test\")\r\ndef test_command(*args):\r\n test_convar.set_string(\"3\")\r\n```\r\n\r\nOutput;\r\n```\r\n$ sp plugin load test1\r\n[SP] Loading plugin 'test1'...\r\n[SP] Successfully loaded plugin 'test1'.\r\n\r\n$ test_convar\r\n\"test_convar\" = \"1\" - Test Convar(test1).\r\n\r\n$ sp plugin load test2\r\n[SP] Loading plugin 'test2'...\r\n[SP] Successfully loaded plugin 'test2'.\r\n\r\n$ sp plugin unload test1\r\n[SP] Unloading plugin 'test1'...\r\n[SP] Successfully unloaded plugin 'test1'.\r\n\r\n$ set_test\r\nThread 1 \"srcds_linux\" received signal SIGSEGV, Segmentation fault.\r\n0xf076d5e5 in boost::python::objects::polymorphic_id_generator\u003cConVar\u003e::execute(void*) ()\r\n```\r\n\r\nThe same problem occurs with the wrapping plugin for ConVars.\r\n\r\nThe root of the problem lies in the fact that ConVar(str) returns an existing registered ConVar.\r\nhttps://github.com/Source-Python-Dev-Team/Source.Python/blob/02e34907fc86036228d132526edcd8f847a0650a/src/core/modules/cvars/cvars.h#L95-L104\r\n\r\nIn the Valve Server Plugin, the ConVar used by the plugin is created each time it is loaded, and released when it is unloaded. Also, when accessing a ConVar that already exists, the plugin retrieves the ConVar from ICvar.FindVar(g_pCVar-\u003eFindVar) and checks if it is valid before accessing it. However, SourcePython's ConVar(str) and SourceMod's CreateConVar return an existing ConVar, so if there are overlapping ConVars, intentionally or unintentionally, the plugin will own a single ConVar, resulting in a crash.\r\n\r\nUnfortunately, ConVar(str) is used by many plugins to access an existing ConVar instead of cvar.find_var which should be used, and it is not possible to not return an existing ConVar without causing a major compatibility break.\r\n\r\nBut either way, when ConVar overlaps, the parent is set and the children access the parent, so when the parent is released, this also causes a crash. (This has been disabled in 02e34907fc86036228d132526edcd8f847a0650a, but should not be disabled for warnings.)\r\nhttps://github.com/Source-Python-Dev-Team/Source.Python/blob/02e34907fc86036228d132526edcd8f847a0650a/src/core/modules/commands/commands_server.cpp#L54-L62\r\n\r\nWe should stop releasing ConVar when unloading plugins, and if we do release it, at least it should be done when unloading Source.Python VSP, so that plugins can work safely. However, if we want to be compatible with SourceMod, I think we should prohibit release of ConVar itself.","author":{"url":"https://github.com/CookStar","@type":"Person","name":"CookStar"},"datePublished":"2021-10-30T09:58:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/430/Source.Python/issues/430"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b2be5c6b-8979-f201-cb6c-28db390a86d4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83E8:B32AB:2300FB3:2E97A04:6970639F |
| html-safe-nonce | fd579f8c3921fb82deed70e4d4e8f78716c23535cda4f22aee5fc57fca6620ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0U4OkIzMkFCOjIzMDBGQjM6MkU5N0EwNDo2OTcwNjM5RiIsInZpc2l0b3JfaWQiOiI1ODg0NDg1MjIwMjkwMjkwNTkyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | eb26981dcd7d3988a20f1641d652e2cc22dee850a961842096cf6f97f99496d2 |
| hovercard-subject-tag | issue:1040104474 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Source-Python-Dev-Team/Source.Python/430/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d45b541a240503ad8b6f1cc44970eeacbfbf03f61f23e74927baf3d0b645a81e/Source-Python-Dev-Team/Source.Python/issues/430 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d45b541a240503ad8b6f1cc44970eeacbfbf03f61f23e74927baf3d0b645a81e/Source-Python-Dev-Team/Source.Python/issues/430 |
| og:image:alt | This is an issue derived from #421 and introduced by 02e3490. There is a long discussion going on in #421, and I've created an issue for the record. The main issue is due to Source.Python releasing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CookStar |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9920a62ba22d06470388e2904804fb7e5ec51c9e35f81784e9191394c74b2bd2 |
| turbo-cache-control | no-preview |
| go-import | github.com/Source-Python-Dev-Team/Source.Python git https://github.com/Source-Python-Dev-Team/Source.Python.git |
| octolytics-dimension-user_id | 5440368 |
| octolytics-dimension-user_login | Source-Python-Dev-Team |
| octolytics-dimension-repository_id | 12771934 |
| octolytics-dimension-repository_nwo | Source-Python-Dev-Team/Source.Python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 12771934 |
| octolytics-dimension-repository_network_root_nwo | Source-Python-Dev-Team/Source.Python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7d6181066430cc06553c8396ca201e194ae33cb9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width