{"action":"created","issue":{"url":"https://api.github.com/repos/mysensors/NodeManager/issues/343","repository_url":"https://api.github.com/repos/mysensors/NodeManager","labels_url":"https://api.github.com/repos/mysensors/NodeManager/issues/343/labels{/name}","comments_url":"https://api.github.com/repos/mysensors/NodeManager/issues/343/comments","events_url":"https://api.github.com/repos/mysensors/NodeManager/issues/343/events","html_url":"https://github.com/mysensors/NodeManager/issues/343","id":310216022,"number":343,"title":"ESP8266 gateway crashes when configuration reply received from child node","user":{"login":"mitchmitchell","id":1643589,"avatar_url":"https://avatars0.githubusercontent.com/u/1643589?v=4","gravatar_id":"","url":"https://api.github.com/users/mitchmitchell","html_url":"https://github.com/mitchmitchell","followers_url":"https://api.github.com/users/mitchmitchell/followers","following_url":"https://api.github.com/users/mitchmitchell/following{/other_user}","gists_url":"https://api.github.com/users/mitchmitchell/gists{/gist_id}","starred_url":"https://api.github.com/users/mitchmitchell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitchmitchell/subscriptions","organizations_url":"https://api.github.com/users/mitchmitchell/orgs","repos_url":"https://api.github.com/users/mitchmitchell/repos","events_url":"https://api.github.com/users/mitchmitchell/events{/privacy}","received_events_url":"https://api.github.com/users/mitchmitchell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-31T06:06:51Z","updated_at":"2018-03-31T07:43:31Z","closed_at":null,"author_association":"NONE","body":"I am testing sending a configuration message to a subordinate node of my ESP8266 gateway device to setIsMetric to one and back to zero.  The gateway device handles the message sent to it fine and relays it to the subordinate HyTiny which successfully changes its mode to metric and back as expected.  However when the gateway receives the reply message from the HyTiny board it crashes.  The message the HyTiny sends is:\r\n```\r\nSEND D=0 I=200 C=0 T=48 S= I=0 F=0.00\r\n1240480 TSF:MSG:SEND,102-102-0-0,s=200,c=1,t=48,pt=5,l=4,sg=0,ft=0,st=OK:22\r\n```\r\nWhen the gateway receives this message it crashes in the call to strtok_r at line or near line 191 at the statement below because at that point the value of the pointer string is zero.\r\n\r\n`_child_id = atoi(strtok_r(const_cast<char*>(string), \",\", &ptr));`\r\n\r\nThis is in the function:\r\n```\r\n// contructor, tokenize a request in the format \"child_id,function,value\"\r\nRequest::Request(int recipient_child_id, const char* string) {\r\n```\r\n\r\nI'm afraid I don't have much to add at this point, I only just realized the crash was happening on the reply from the HyTiny rather than on the message to the gateway from the controller.\r\n\r\nI will look further into the code to try and understand how the reply is getting constructed."},"comment":{"url":"https://api.github.com/repos/mysensors/NodeManager/issues/comments/377674149","html_url":"https://github.com/mysensors/NodeManager/issues/343#issuecomment-377674149","issue_url":"https://api.github.com/repos/mysensors/NodeManager/issues/343","id":377674149,"user":{"login":"mitchmitchell","id":1643589,"avatar_url":"https://avatars0.githubusercontent.com/u/1643589?v=4","gravatar_id":"","url":"https://api.github.com/users/mitchmitchell","html_url":"https://github.com/mitchmitchell","followers_url":"https://api.github.com/users/mitchmitchell/followers","following_url":"https://api.github.com/users/mitchmitchell/following{/other_user}","gists_url":"https://api.github.com/users/mitchmitchell/gists{/gist_id}","starred_url":"https://api.github.com/users/mitchmitchell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitchmitchell/subscriptions","organizations_url":"https://api.github.com/users/mitchmitchell/orgs","repos_url":"https://api.github.com/users/mitchmitchell/repos","events_url":"https://api.github.com/users/mitchmitchell/events{/privacy}","received_events_url":"https://api.github.com/users/mitchmitchell/received_events","type":"User","site_admin":false},"created_at":"2018-03-31T07:43:31Z","updated_at":"2018-03-31T07:43:31Z","author_association":"NONE","body":"Ok I stopped the crashing with apparently no other side effects by adding a check for a null string in the `void SensorConfiguration::onReceive(MyMessage* message)` function, see below:\r\n\r\n\r\nvoid SensorConfiguration::onReceive(MyMessage* message) {\r\n  // expect a REQ, V_CUSTOM message\r\n  if (message->getCommand() != C_REQ && message->type != V_CUSTOM) return;\r\n  // parse the request\r\n  **if (message->getString() == NULL) return;**\r\n  Request request = Request(message->sensor,message->getString());\r\n  int function = request.getFunction();\r\n  int child_id = request.getChildId();\r\n  // if the message is for the board itself\r\n\r\n"}}
{"actor":{"display_login":"mitchmitchell"}}