{"action":"created","issue":{"url":"https://api.github.com/repos/tmux/tmux/issues/291","labels_url":"https://api.github.com/repos/tmux/tmux/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/tmux/tmux/issues/291/comments","events_url":"https://api.github.com/repos/tmux/tmux/issues/291/events","html_url":"https://github.com/tmux/tmux/issues/291","id":129933074,"number":291,"title":"new-session causes SEGFAULT since 5caec30","user":{"login":"mgraczyk","id":1097264,"avatar_url":"https://avatars.githubusercontent.com/u/1097264?v=3","gravatar_id":"","url":"https://api.github.com/users/mgraczyk","html_url":"https://github.com/mgraczyk","followers_url":"https://api.github.com/users/mgraczyk/followers","following_url":"https://api.github.com/users/mgraczyk/following{/other_user}","gists_url":"https://api.github.com/users/mgraczyk/gists{/gist_id}","starred_url":"https://api.github.com/users/mgraczyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgraczyk/subscriptions","organizations_url":"https://api.github.com/users/mgraczyk/orgs","repos_url":"https://api.github.com/users/mgraczyk/repos","events_url":"https://api.github.com/users/mgraczyk/events{/privacy}","received_events_url":"https://api.github.com/users/mgraczyk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-30T02:59:15Z","updated_at":"2016-01-30T05:35:01Z","closed_at":null,"body":"Running new-session with an invalid target session causes the tmux server to segfault. This error was introduced in commit `5caec30`. This bug is extremely annoying because all sessions are lost when the server crashes.\r\n\r\n**Steps To Reproduce:**\r\n- Checkout tmux at current HEAD and make sure server is not running.\r\n\r\n ```\r\ncd tmux\r\ngit checkout 404379049a4cb5480c2b1c19634c869e46feb220\r\ngit clean -xdf\r\n./autoconf.sh && ./configure && make -j\r\npkill tmux\r\n```\r\n\r\n- Create a named detached session.\r\n\r\n```\r\n./tmux new-session -d -s name\r\n```\r\n-  Check that tmux server is running\r\n\r\n```\r\nps -A | grep tmux\r\n```\r\n- Try to create a new session grouped with a non-existent session\r\n\r\n```\r\n./tmux new-session -s new_name -t nonexistent_name\r\n```\r\n\r\n**Expected Results:**\r\nThe tmux client started in step 4 should output \"no current session\" and exit.\r\n\r\n**Actual Results:**\r\nThe tmux server crashes with a segfault at `session.c:578` because target is NULL.\r\nThe tmux client outputs \"lost server\".\r\n\r\n\r\n**Analysis**\r\nFrom bisecting, it looks like the problem was introduced in commit `5caec30`. The problem appears to be this change:\r\n\r\n```\r\n-               if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)\r\n-                       return (CMD_RETURN_ERROR);\r\n+               /*\r\n+                * cmd_prepare() will fail if the session cannot be found,\r\n+                * hence always return success here.\r\n+                */\r\n```\r\n\r\nIn fact, cmd_prepare_state_flag does not fail when the session is not found.\r\nI am not familiar enough with the code to know for sure that this is the cause or what the solution should be. Please take it with some skepticism. \r\n\r\nMy bisect script is attached.\r\n[bisect.sh.txt](https://github.com/tmux/tmux/files/110650/bisect.sh.txt)\r\n\r\n\r\n\r\nI am particularly concerned with this bug and others like it because it caused me to lose my tmux server state. That is the emotional equivalent of dropping a stack of papers with no page numbers down a flight of stairs."},"comment":{"url":"https://api.github.com/repos/tmux/tmux/issues/comments/177076673","html_url":"https://github.com/tmux/tmux/issues/291#issuecomment-177076673","issue_url":"https://api.github.com/repos/tmux/tmux/issues/291","id":177076673,"user":{"login":"jungle-boogie","id":1111743,"avatar_url":"https://avatars.githubusercontent.com/u/1111743?v=3","gravatar_id":"","url":"https://api.github.com/users/jungle-boogie","html_url":"https://github.com/jungle-boogie","followers_url":"https://api.github.com/users/jungle-boogie/followers","following_url":"https://api.github.com/users/jungle-boogie/following{/other_user}","gists_url":"https://api.github.com/users/jungle-boogie/gists{/gist_id}","starred_url":"https://api.github.com/users/jungle-boogie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jungle-boogie/subscriptions","organizations_url":"https://api.github.com/users/jungle-boogie/orgs","repos_url":"https://api.github.com/users/jungle-boogie/repos","events_url":"https://api.github.com/users/jungle-boogie/events{/privacy}","received_events_url":"https://api.github.com/users/jungle-boogie/received_events","type":"User","site_admin":false},"created_at":"2016-01-30T05:35:01Z","updated_at":"2016-01-30T05:35:01Z","body":"Hi,\r\n\r\nI can't reproduce this and I'm on head. \r\n\r\n`% tmux new-session -s new_name -t nonexistent_name`\r\n`can't find session nonexistent_name`"}}