{"action":"created","comment":{"url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/comments/27460038","id":27460038,"diff_hunk":"@@ -299,18 +300,16 @@ static int resolv_conf_dns(struct ipforward_data *ipforward)\n \n static int checklink(void)\n {\n-   char *dest = malloc( 32 * sizeof(char)) ;\n-   int ret = 0;\n-\n-   readlink(\"/etc/udhcpd.conf\", dest, 32);\n-   if(dest != NULL)\n-   {\n-\tstrcpy(&dest[31], \"\\0\");\n-\tret = (strcmp(dest, UDHCP_CONFIG_PATH));\n-   }\n-   free(dest);\n-\n-   return(ret);\n+  int ret = -1;\n+  const size_t bufsiz = 32;\n+  char *dest = malloc(bufsiz);","path":"src/usb_moded-network.c","position":26,"original_position":26,"commit_id":"8f02c6dd3f9e60e38b9d0d9f3f2d2ba73d754d3c","original_commit_id":"8f02c6dd3f9e60e38b9d0d9f3f2d2ba73d754d3c","user":{"login":"monich","id":5909522,"avatar_url":"https://avatars.githubusercontent.com/u/5909522?v=3","gravatar_id":"","url":"https://api.github.com/users/monich","html_url":"https://github.com/monich","followers_url":"https://api.github.com/users/monich/followers","following_url":"https://api.github.com/users/monich/following{/other_user}","gists_url":"https://api.github.com/users/monich/gists{/gist_id}","starred_url":"https://api.github.com/users/monich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monich/subscriptions","organizations_url":"https://api.github.com/users/monich/orgs","repos_url":"https://api.github.com/users/monich/repos","events_url":"https://api.github.com/users/monich/events{/privacy}","received_events_url":"https://api.github.com/users/monich/received_events","type":"User","site_admin":false},"body":"This heap allocation is there for the same reason why it was there in the original code. I don't know why it was there.\r\n\r\nIf I wrote the original code, I would either allocate a small amount (such as 32 bytes) on stack or a large amount (such as PATH_MAX) from the heap, to reduce the chance of running out of stack space.\r\n\r\nWhen I'm fixing a problem, I am trying to be consistent with the existing code.","created_at":"2015-03-31T08:20:35Z","updated_at":"2015-03-31T08:20:35Z","html_url":"https://github.com/nemomobile/usb-moded/pull/26#discussion_r27460038","pull_request_url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/comments/27460038"},"html":{"href":"https://github.com/nemomobile/usb-moded/pull/26#discussion_r27460038"},"pull_request":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26","id":32258651,"html_url":"https://github.com/nemomobile/usb-moded/pull/26","diff_url":"https://github.com/nemomobile/usb-moded/pull/26.diff","patch_url":"https://github.com/nemomobile/usb-moded/pull/26.patch","issue_url":"https://api.github.com/repos/nemomobile/usb-moded/issues/26","number":26,"state":"open","locked":false,"title":"Fix couple of errors in checklink()","user":{"login":"monich","id":5909522,"avatar_url":"https://avatars.githubusercontent.com/u/5909522?v=3","gravatar_id":"","url":"https://api.github.com/users/monich","html_url":"https://github.com/monich","followers_url":"https://api.github.com/users/monich/followers","following_url":"https://api.github.com/users/monich/following{/other_user}","gists_url":"https://api.github.com/users/monich/gists{/gist_id}","starred_url":"https://api.github.com/users/monich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monich/subscriptions","organizations_url":"https://api.github.com/users/monich/orgs","repos_url":"https://api.github.com/users/monich/repos","events_url":"https://api.github.com/users/monich/events{/privacy}","received_events_url":"https://api.github.com/users/monich/received_events","type":"User","site_admin":false},"body":"1. Removed useless check for NULL after the pointer has already been used\r\n2. Correctly NULL-terminate buffer filled by `readlink()`\r\n\r\nThe latter was was causing valgrind warnings like this:\r\n```\r\n==32357== Conditional jump or move depends on uninitialised value(s)\r\n==32357==    at 0x484456C: strcmp (vg_replace_strmem.c:755)\r\n==32357==    by 0x10E717: checklink (usb_moded-network.c:309)\r\n==32357==    by 0x10E717: write_udhcpd_conf (usb_moded-network.c:395)\r\n==32357==    by 0x10E717: usb_network_set_up_dhcpd (usb_moded-network.c:804)\r\n==32357==    by 0x10F5DF: set_dynamic_mode (usb_moded-modesetting.c:446)\r\n==32357==    by 0x10B59F: set_usb_mode (usb_moded.c:379)\r\n==32357==    by 0x10BEE7: msg_handler (usb_moded-dbus.c:108)\r\n==32357==    by 0x48A1567: dbus_connection_dispatch (dbus-connection.c:4658)\r\n==32357==    by 0x48736F7: message_queue_dispatch (dbus-gmain.c:90)\r\n==32357==    by 0x4913B85: g_main_dispatch (gmain.c:3066)\r\n==32357==    by 0x4913B85: g_main_context_dispatch (gmain.c:3642)\r\n==32357==    by 0x4913E11: g_main_context_iterate.isra.5 (gmain.c:3713)\r\n==32357==    by 0x49141D3: g_main_loop_run (gmain.c:3907)\r\n==32357==    by 0x10AF63: main (usb_moded.c:991)\r\n```","created_at":"2015-03-30T19:28:06Z","updated_at":"2015-03-31T08:20:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71b9d589abb3f9e1a5584661457fc329bb115b7d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26/commits","review_comments_url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26/comments","review_comment_url":"https://api.github.com/repos/nemomobile/usb-moded/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nemomobile/usb-moded/issues/26/comments","statuses_url":"https://api.github.com/repos/nemomobile/usb-moded/statuses/8f02c6dd3f9e60e38b9d0d9f3f2d2ba73d754d3c","head":{"label":"monich:checklink","ref":"checklink","sha":"8f02c6dd3f9e60e38b9d0d9f3f2d2ba73d754d3c","user":{"login":"monich","id":5909522,"avatar_url":"https://avatars.githubusercontent.com/u/5909522?v=3","gravatar_id":"","url":"https://api.github.com/users/monich","html_url":"https://github.com/monich","followers_url":"https://api.github.com/users/monich/followers","following_url":"https://api.github.com/users/monich/following{/other_user}","gists_url":"https://api.github.com/users/monich/gists{/gist_id}","starred_url":"https://api.github.com/users/monich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monich/subscriptions","organizations_url":"https://api.github.com/users/monich/orgs","repos_url":"https://api.github.com/users/monich/repos","events_url":"https://api.github.com/users/monich/events{/privacy}","received_events_url":"https://api.github.com/users/monich/received_events","type":"User","site_admin":false},"repo":{"id":33132787,"name":"usb-moded","full_name":"monich/usb-moded","owner":{"login":"monich","id":5909522,"avatar_url":"https://avatars.githubusercontent.com/u/5909522?v=3","gravatar_id":"","url":"https://api.github.com/users/monich","html_url":"https://github.com/monich","followers_url":"https://api.github.com/users/monich/followers","following_url":"https://api.github.com/users/monich/following{/other_user}","gists_url":"https://api.github.com/users/monich/gists{/gist_id}","starred_url":"https://api.github.com/users/monich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monich/subscriptions","organizations_url":"https://api.github.com/users/monich/orgs","repos_url":"https://api.github.com/users/monich/repos","events_url":"https://api.github.com/users/monich/events{/privacy}","received_events_url":"https://api.github.com/users/monich/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/monich/usb-moded","description":"This is the source repository for usb_moded. This is a daemon which can hanlde setting different usb profiles with gadget drivers. It can start extra services needed through dbus, upstart or systemd. Moreover it can configure networking and USB tethering. Detailed information and documentation is in the docs folder.","fork":true,"url":"https://api.github.com/repos/monich/usb-moded","forks_url":"https://api.github.com/repos/monich/usb-moded/forks","keys_url":"https://api.github.com/repos/monich/usb-moded/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monich/usb-moded/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monich/usb-moded/teams","hooks_url":"https://api.github.com/repos/monich/usb-moded/hooks","issue_events_url":"https://api.github.com/repos/monich/usb-moded/issues/events{/number}","events_url":"https://api.github.com/repos/monich/usb-moded/events","assignees_url":"https://api.github.com/repos/monich/usb-moded/assignees{/user}","branches_url":"https://api.github.com/repos/monich/usb-moded/branches{/branch}","tags_url":"https://api.github.com/repos/monich/usb-moded/tags","blobs_url":"https://api.github.com/repos/monich/usb-moded/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monich/usb-moded/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monich/usb-moded/git/refs{/sha}","trees_url":"https://api.github.com/repos/monich/usb-moded/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monich/usb-moded/statuses/{sha}","languages_url":"https://api.github.com/repos/monich/usb-moded/languages","stargazers_url":"https://api.github.com/repos/monich/usb-moded/stargazers","contributors_url":"https://api.github.com/repos/monich/usb-moded/contributors","subscribers_url":"https://api.github.com/repos/monich/usb-moded/subscribers","subscription_url":"https://api.github.com/repos/monich/usb-moded/subscription","commits_url":"https://api.github.com/repos/monich/usb-moded/commits{/sha}","git_commits_url":"https://api.github.com/repos/monich/usb-moded/git/commits{/sha}","comments_url":"https://api.github.com/repos/monich/usb-moded/comments{/number}","issue_comment_url":"https://api.github.com/repos/monich/usb-moded/issues/comments{/number}","contents_url":"https://api.github.com/repos/monich/usb-moded/contents/{+path}","compare_url":"https://api.github.com/repos/monich/usb-moded/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monich/usb-moded/merges","archive_url":"https://api.github.com/repos/monich/usb-moded/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monich/usb-moded/downloads","issues_url":"https://api.github.com/repos/monich/usb-moded/issues{/number}","pulls_url":"https://api.github.com/repos/monich/usb-moded/pulls{/number}","milestones_url":"https://api.github.com/repos/monich/usb-moded/milestones{/number}","notifications_url":"https://api.github.com/repos/monich/usb-moded/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monich/usb-moded/labels{/name}","releases_url":"https://api.github.com/repos/monich/usb-moded/releases{/id}","created_at":"2015-03-30T15:54:05Z","updated_at":"2015-03-30T19:17:18Z","pushed_at":"2015-03-30T20:03:04Z","git_url":"git://github.com/monich/usb-moded.git","ssh_url":"git@github.com:monich/usb-moded.git","clone_url":"https://github.com/monich/usb-moded.git","svn_url":"https://github.com/monich/usb-moded","homepage":"","size":1044,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nemomobile:master","ref":"master","sha":"b0df07af9beed8968fe921ab8f260575018aa65f","user":{"login":"nemomobile","id":1088947,"avatar_url":"https://avatars.githubusercontent.com/u/1088947?v=3","gravatar_id":"","url":"https://api.github.com/users/nemomobile","html_url":"https://github.com/nemomobile","followers_url":"https://api.github.com/users/nemomobile/followers","following_url":"https://api.github.com/users/nemomobile/following{/other_user}","gists_url":"https://api.github.com/users/nemomobile/gists{/gist_id}","starred_url":"https://api.github.com/users/nemomobile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nemomobile/subscriptions","organizations_url":"https://api.github.com/users/nemomobile/orgs","repos_url":"https://api.github.com/users/nemomobile/repos","events_url":"https://api.github.com/users/nemomobile/events{/privacy}","received_events_url":"https://api.github.com/users/nemomobile/received_events","type":"Organization","site_admin":false},"repo":{"id":10123099,"name":"usb-moded","full_name":"nemomobile/usb-moded","owner":{"login":"nemomobile","id":1088947,"avatar_url":"https://avatars.githubusercontent.com/u/1088947?v=3","gravatar_id":"","url":"https://api.github.com/users/nemomobile","html_url":"https://github.com/nemomobile","followers_url":"https://api.github.com/users/nemomobile/followers","following_url":"https://api.github.com/users/nemomobile/following{/other_user}","gists_url":"https://api.github.com/users/nemomobile/gists{/gist_id}","starred_url":"https://api.github.com/users/nemomobile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nemomobile/subscriptions","organizations_url":"https://api.github.com/users/nemomobile/orgs","repos_url":"https://api.github.com/users/nemomobile/repos","events_url":"https://api.github.com/users/nemomobile/events{/privacy}","received_events_url":"https://api.github.com/users/nemomobile/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nemomobile/usb-moded","description":"This is the source repository for usb_moded. This is a daemon which can hanlde setting different usb profiles with gadget drivers. It can start extra services needed through dbus, upstart or systemd. Moreover it can configure networking and USB tethering. Detailed information and documentation is in the docs folder.","fork":false,"url":"https://api.github.com/repos/nemomobile/usb-moded","forks_url":"https://api.github.com/repos/nemomobile/usb-moded/forks","keys_url":"https://api.github.com/repos/nemomobile/usb-moded/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nemomobile/usb-moded/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nemomobile/usb-moded/teams","hooks_url":"https://api.github.com/repos/nemomobile/usb-moded/hooks","issue_events_url":"https://api.github.com/repos/nemomobile/usb-moded/issues/events{/number}","events_url":"https://api.github.com/repos/nemomobile/usb-moded/events","assignees_url":"https://api.github.com/repos/nemomobile/usb-moded/assignees{/user}","branches_url":"https://api.github.com/repos/nemomobile/usb-moded/branches{/branch}","tags_url":"https://api.github.com/repos/nemomobile/usb-moded/tags","blobs_url":"https://api.github.com/repos/nemomobile/usb-moded/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nemomobile/usb-moded/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nemomobile/usb-moded/git/refs{/sha}","trees_url":"https://api.github.com/repos/nemomobile/usb-moded/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nemomobile/usb-moded/statuses/{sha}","languages_url":"https://api.github.com/repos/nemomobile/usb-moded/languages","stargazers_url":"https://api.github.com/repos/nemomobile/usb-moded/stargazers","contributors_url":"https://api.github.com/repos/nemomobile/usb-moded/contributors","subscribers_url":"https://api.github.com/repos/nemomobile/usb-moded/subscribers","subscription_url":"https://api.github.com/repos/nemomobile/usb-moded/subscription","commits_url":"https://api.github.com/repos/nemomobile/usb-moded/commits{/sha}","git_commits_url":"https://api.github.com/repos/nemomobile/usb-moded/git/commits{/sha}","comments_url":"https://api.github.com/repos/nemomobile/usb-moded/comments{/number}","issue_comment_url":"https://api.github.com/repos/nemomobile/usb-moded/issues/comments{/number}","contents_url":"https://api.github.com/repos/nemomobile/usb-moded/contents/{+path}","compare_url":"https://api.github.com/repos/nemomobile/usb-moded/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nemomobile/usb-moded/merges","archive_url":"https://api.github.com/repos/nemomobile/usb-moded/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nemomobile/usb-moded/downloads","issues_url":"https://api.github.com/repos/nemomobile/usb-moded/issues{/number}","pulls_url":"https://api.github.com/repos/nemomobile/usb-moded/pulls{/number}","milestones_url":"https://api.github.com/repos/nemomobile/usb-moded/milestones{/number}","notifications_url":"https://api.github.com/repos/nemomobile/usb-moded/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nemomobile/usb-moded/labels{/name}","releases_url":"https://api.github.com/repos/nemomobile/usb-moded/releases{/id}","created_at":"2013-05-17T12:43:56Z","updated_at":"2015-03-31T06:28:11Z","pushed_at":"2015-03-31T06:28:11Z","git_url":"git://github.com/nemomobile/usb-moded.git","ssh_url":"git@github.com:nemomobile/usb-moded.git","clone_url":"https://github.com/nemomobile/usb-moded.git","svn_url":"https://github.com/nemomobile/usb-moded","homepage":"","size":2514,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":1,"forks":13,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26"},"html":{"href":"https://github.com/nemomobile/usb-moded/pull/26"},"issue":{"href":"https://api.github.com/repos/nemomobile/usb-moded/issues/26"},"comments":{"href":"https://api.github.com/repos/nemomobile/usb-moded/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nemomobile/usb-moded/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/nemomobile/usb-moded/statuses/8f02c6dd3f9e60e38b9d0d9f3f2d2ba73d754d3c"}}}}