{"action":"created","comment":{"url":"https://api.github.com/repos/cisco/libsrtp/pulls/comments/167225351","pull_request_review_id":95408284,"id":167225351,"diff_hunk":"@@ -147,53 +147,141 @@ unsigned int srtp_get_version()\n     return rv;\n }\n \n-/* Release (maybe partially allocated) stream. */\n-static void srtp_stream_free(srtp_stream_ctx_t *str)\n+srtp_err_status_t srtp_stream_dealloc(srtp_stream_ctx_t *stream,\n+                                      const srtp_stream_ctx_t *stream_template)\n {\n+    srtp_err_status_t status;\n     unsigned int i = 0;\n     srtp_session_keys_t *session_keys = NULL;\n+    srtp_session_keys_t *template_session_keys = NULL;\n \n-    if (str->session_keys) {\n-        for (i = 0; i < str->num_master_keys; i++) {\n-            session_keys = &str->session_keys[i];\n+    /*\n+     * we use a conservative deallocation strategy - if any deallocation\n+     * fails, then we report that fact without trying to deallocate\n+     * anything else\n+     */\n+    if (stream->session_keys) {\n+        for (i = 0; i < stream->num_master_keys; i++) {\n+            session_keys = &stream->session_keys[i];\n \n-            if (session_keys->rtp_xtn_hdr_cipher) {\n-                srtp_cipher_dealloc(session_keys->rtp_xtn_hdr_cipher);\n+            if (stream_template) {\n+                template_session_keys = &stream_template->session_keys[i];\n+            } else {\n+                template_session_keys = NULL;\n             }\n \n-            if (session_keys->rtcp_cipher) {\n-                srtp_cipher_dealloc(session_keys->rtcp_cipher);\n+            /*\n+            * deallocate cipher, if it is not the same as that in template\n+            */\n+            if (template_session_keys &&\n+                session_keys->rtp_cipher == template_session_keys->rtp_cipher) {\n+                /* do nothing */\n+            } else if (session_keys->rtp_cipher) {\n+                status = srtp_cipher_dealloc(session_keys->rtp_cipher);\n+                if (status)\n+                    return status;\n+            }\n+\n+            /*\n+             * deallocate auth function, if it is not the same as that in\n+             * template\n+             */\n+            if (template_session_keys &&\n+                session_keys->rtp_auth == template_session_keys->rtp_auth) {\n+                /* do nothing */\n+            } else if (session_keys->rtp_auth) {\n+                status = srtp_auth_dealloc(session_keys->rtp_auth);\n+                if (status)\n+                    return status;\n             }\n \n-            if (session_keys->rtcp_auth) {\n-                srtp_auth_dealloc(session_keys->rtcp_auth);\n+            if (template_session_keys &&\n+                session_keys->rtp_xtn_hdr_cipher ==\n+                    template_session_keys->rtp_xtn_hdr_cipher) {\n+                /* do nothing */\n+            } else if (session_keys->rtp_xtn_hdr_cipher) {\n+                status = srtp_cipher_dealloc(session_keys->rtp_xtn_hdr_cipher);\n+                if (status)\n+                    return status;\n             }\n \n-            if (session_keys->rtp_cipher) {\n-                srtp_cipher_dealloc(session_keys->rtp_cipher);\n+            /*\n+             * deallocate rtcp cipher, if it is not the same as that in\n+             * template\n+             */\n+            if (template_session_keys &&\n+                session_keys->rtcp_cipher ==\n+                    template_session_keys->rtcp_cipher) {\n+                /* do nothing */\n+            } else if (session_keys->rtcp_cipher) {\n+                status = srtp_cipher_dealloc(session_keys->rtcp_cipher);\n+                if (status)\n+                    return status;\n             }\n \n-            if (session_keys->rtp_auth) {\n-                srtp_auth_dealloc(session_keys->rtp_auth);\n+            /*\n+             * deallocate rtcp auth function, if it is not the same as that in\n+             * template\n+             */\n+            if (template_session_keys &&\n+                session_keys->rtcp_auth == template_session_keys->rtcp_auth) {\n+                /* do nothing */\n+            } else if (session_keys->rtcp_auth) {\n+                status = srtp_auth_dealloc(session_keys->rtcp_auth);\n+                if (status)\n+                    return status;\n             }\n \n+            /*\n+             * zeroize the salt value\n+             */\n+            octet_string_set_to_zero(session_keys->salt, SRTP_AEAD_SALT_LEN);\n+            octet_string_set_to_zero(session_keys->c_salt, SRTP_AEAD_SALT_LEN);\n+\n             if (session_keys->mki_id) {\n+                octet_string_set_to_zero(session_keys->mki_id,\n+                                         session_keys->mki_size);\n                 srtp_crypto_free(session_keys->mki_id);\n+                session_keys->mki_id = NULL;\n             }\n \n-            if (session_keys->limit) {\n+            /*\n+             * deallocate key usage limit, if it is not the same as that in\n+             * template\n+             */\n+            if (template_session_keys &&\n+                session_keys->limit == template_session_keys->limit) {\n+                /* do nothing */\n+            } else if (session_keys->limit) {\n                 srtp_crypto_free(session_keys->limit);\n             }\n         }\n+    }\n \n-        srtp_crypto_free(str->session_keys);\n+    if (stream_template &&\n+        stream->session_keys == stream_template->session_keys) {\n+        /* do nothing */\n+    } else {\n+        srtp_crypto_free(stream->session_keys);\n     }\n \n-    if (str->enc_xtn_hdr) {\n-        srtp_crypto_free(str->enc_xtn_hdr);\n+    status = srtp_rdbx_dealloc(&stream->rtp_rdbx);\n+    if (status)\n+        return status;\n+\n+    /* DAM - need to deallocate EKT here */","path":"srtp/srtp.c","position":146,"original_position":145,"commit_id":"c995df45427efb149701548ea2d77a4d155b04e5","original_commit_id":"8ec13a7eb1fa099daef61745533f4661277c1e16","user":{"login":"thisisG","id":5999908,"avatar_url":"https://avatars1.githubusercontent.com/u/5999908?v=4","gravatar_id":"","url":"https://api.github.com/users/thisisG","html_url":"https://github.com/thisisG","followers_url":"https://api.github.com/users/thisisG/followers","following_url":"https://api.github.com/users/thisisG/following{/other_user}","gists_url":"https://api.github.com/users/thisisG/gists{/gist_id}","starred_url":"https://api.github.com/users/thisisG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thisisG/subscriptions","organizations_url":"https://api.github.com/users/thisisG/orgs","repos_url":"https://api.github.com/users/thisisG/repos","events_url":"https://api.github.com/users/thisisG/events{/privacy}","received_events_url":"https://api.github.com/users/thisisG/received_events","type":"User","site_admin":false},"body":"Might as well implement the EKT deallocation now?","created_at":"2018-02-09T13:22:01Z","updated_at":"2018-02-09T13:24:40Z","html_url":"https://github.com/cisco/libsrtp/pull/398#discussion_r167225351","pull_request_url":"https://api.github.com/repos/cisco/libsrtp/pulls/398","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/comments/167225351"},"html":{"href":"https://github.com/cisco/libsrtp/pull/398#discussion_r167225351"},"pull_request":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/398"}},"in_reply_to_id":167223207},"pull_request":{"url":"https://api.github.com/repos/cisco/libsrtp/pulls/398","id":165308058,"html_url":"https://github.com/cisco/libsrtp/pull/398","diff_url":"https://github.com/cisco/libsrtp/pull/398.diff","patch_url":"https://github.com/cisco/libsrtp/pull/398.patch","issue_url":"https://api.github.com/repos/cisco/libsrtp/issues/398","number":398,"state":"open","locked":false,"title":"Memory access fixes","user":{"login":"pabuhler","id":15016732,"avatar_url":"https://avatars1.githubusercontent.com/u/15016732?v=4","gravatar_id":"","url":"https://api.github.com/users/pabuhler","html_url":"https://github.com/pabuhler","followers_url":"https://api.github.com/users/pabuhler/followers","following_url":"https://api.github.com/users/pabuhler/following{/other_user}","gists_url":"https://api.github.com/users/pabuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/pabuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabuhler/subscriptions","organizations_url":"https://api.github.com/users/pabuhler/orgs","repos_url":"https://api.github.com/users/pabuhler/repos","events_url":"https://api.github.com/users/pabuhler/events{/privacy}","received_events_url":"https://api.github.com/users/pabuhler/received_events","type":"User","site_admin":false},"body":"This contains a group of fixes to various memory access violations detected using a fuzzer provided by @guidovranken.","created_at":"2018-01-26T08:04:30Z","updated_at":"2018-02-09T13:24:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"39d9a05efde4db018028a5c11b61fb2ea8b88315","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/cisco/libsrtp/pulls/398/commits","review_comments_url":"https://api.github.com/repos/cisco/libsrtp/pulls/398/comments","review_comment_url":"https://api.github.com/repos/cisco/libsrtp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cisco/libsrtp/issues/398/comments","statuses_url":"https://api.github.com/repos/cisco/libsrtp/statuses/c995df45427efb149701548ea2d77a4d155b04e5","head":{"label":"pabuhler:memory-access-fixes","ref":"memory-access-fixes","sha":"c995df45427efb149701548ea2d77a4d155b04e5","user":{"login":"pabuhler","id":15016732,"avatar_url":"https://avatars1.githubusercontent.com/u/15016732?v=4","gravatar_id":"","url":"https://api.github.com/users/pabuhler","html_url":"https://github.com/pabuhler","followers_url":"https://api.github.com/users/pabuhler/followers","following_url":"https://api.github.com/users/pabuhler/following{/other_user}","gists_url":"https://api.github.com/users/pabuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/pabuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabuhler/subscriptions","organizations_url":"https://api.github.com/users/pabuhler/orgs","repos_url":"https://api.github.com/users/pabuhler/repos","events_url":"https://api.github.com/users/pabuhler/events{/privacy}","received_events_url":"https://api.github.com/users/pabuhler/received_events","type":"User","site_admin":false},"repo":{"id":43822887,"name":"libsrtp","full_name":"pabuhler/libsrtp","owner":{"login":"pabuhler","id":15016732,"avatar_url":"https://avatars1.githubusercontent.com/u/15016732?v=4","gravatar_id":"","url":"https://api.github.com/users/pabuhler","html_url":"https://github.com/pabuhler","followers_url":"https://api.github.com/users/pabuhler/followers","following_url":"https://api.github.com/users/pabuhler/following{/other_user}","gists_url":"https://api.github.com/users/pabuhler/gists{/gist_id}","starred_url":"https://api.github.com/users/pabuhler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pabuhler/subscriptions","organizations_url":"https://api.github.com/users/pabuhler/orgs","repos_url":"https://api.github.com/users/pabuhler/repos","events_url":"https://api.github.com/users/pabuhler/events{/privacy}","received_events_url":"https://api.github.com/users/pabuhler/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pabuhler/libsrtp","description":"Library for SRTP (Secure Realtime Transport Protocol) ","fork":true,"url":"https://api.github.com/repos/pabuhler/libsrtp","forks_url":"https://api.github.com/repos/pabuhler/libsrtp/forks","keys_url":"https://api.github.com/repos/pabuhler/libsrtp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pabuhler/libsrtp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pabuhler/libsrtp/teams","hooks_url":"https://api.github.com/repos/pabuhler/libsrtp/hooks","issue_events_url":"https://api.github.com/repos/pabuhler/libsrtp/issues/events{/number}","events_url":"https://api.github.com/repos/pabuhler/libsrtp/events","assignees_url":"https://api.github.com/repos/pabuhler/libsrtp/assignees{/user}","branches_url":"https://api.github.com/repos/pabuhler/libsrtp/branches{/branch}","tags_url":"https://api.github.com/repos/pabuhler/libsrtp/tags","blobs_url":"https://api.github.com/repos/pabuhler/libsrtp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pabuhler/libsrtp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pabuhler/libsrtp/git/refs{/sha}","trees_url":"https://api.github.com/repos/pabuhler/libsrtp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pabuhler/libsrtp/statuses/{sha}","languages_url":"https://api.github.com/repos/pabuhler/libsrtp/languages","stargazers_url":"https://api.github.com/repos/pabuhler/libsrtp/stargazers","contributors_url":"https://api.github.com/repos/pabuhler/libsrtp/contributors","subscribers_url":"https://api.github.com/repos/pabuhler/libsrtp/subscribers","subscription_url":"https://api.github.com/repos/pabuhler/libsrtp/subscription","commits_url":"https://api.github.com/repos/pabuhler/libsrtp/commits{/sha}","git_commits_url":"https://api.github.com/repos/pabuhler/libsrtp/git/commits{/sha}","comments_url":"https://api.github.com/repos/pabuhler/libsrtp/comments{/number}","issue_comment_url":"https://api.github.com/repos/pabuhler/libsrtp/issues/comments{/number}","contents_url":"https://api.github.com/repos/pabuhler/libsrtp/contents/{+path}","compare_url":"https://api.github.com/repos/pabuhler/libsrtp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pabuhler/libsrtp/merges","archive_url":"https://api.github.com/repos/pabuhler/libsrtp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pabuhler/libsrtp/downloads","issues_url":"https://api.github.com/repos/pabuhler/libsrtp/issues{/number}","pulls_url":"https://api.github.com/repos/pabuhler/libsrtp/pulls{/number}","milestones_url":"https://api.github.com/repos/pabuhler/libsrtp/milestones{/number}","notifications_url":"https://api.github.com/repos/pabuhler/libsrtp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pabuhler/libsrtp/labels{/name}","releases_url":"https://api.github.com/repos/pabuhler/libsrtp/releases{/id}","deployments_url":"https://api.github.com/repos/pabuhler/libsrtp/deployments","created_at":"2015-10-07T14:50:02Z","updated_at":"2016-12-12T14:14:30Z","pushed_at":"2018-02-09T10:59:33Z","git_url":"git://github.com/pabuhler/libsrtp.git","ssh_url":"git@github.com:pabuhler/libsrtp.git","clone_url":"https://github.com/pabuhler/libsrtp.git","svn_url":"https://github.com/pabuhler/libsrtp","homepage":null,"size":5123,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"cisco:master","ref":"master","sha":"2761dacf7eb8243afb326cd4efa852219169f350","user":{"login":"cisco","id":1376999,"avatar_url":"https://avatars0.githubusercontent.com/u/1376999?v=4","gravatar_id":"","url":"https://api.github.com/users/cisco","html_url":"https://github.com/cisco","followers_url":"https://api.github.com/users/cisco/followers","following_url":"https://api.github.com/users/cisco/following{/other_user}","gists_url":"https://api.github.com/users/cisco/gists{/gist_id}","starred_url":"https://api.github.com/users/cisco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cisco/subscriptions","organizations_url":"https://api.github.com/users/cisco/orgs","repos_url":"https://api.github.com/users/cisco/repos","events_url":"https://api.github.com/users/cisco/events{/privacy}","received_events_url":"https://api.github.com/users/cisco/received_events","type":"Organization","site_admin":false},"repo":{"id":9087423,"name":"libsrtp","full_name":"cisco/libsrtp","owner":{"login":"cisco","id":1376999,"avatar_url":"https://avatars0.githubusercontent.com/u/1376999?v=4","gravatar_id":"","url":"https://api.github.com/users/cisco","html_url":"https://github.com/cisco","followers_url":"https://api.github.com/users/cisco/followers","following_url":"https://api.github.com/users/cisco/following{/other_user}","gists_url":"https://api.github.com/users/cisco/gists{/gist_id}","starred_url":"https://api.github.com/users/cisco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cisco/subscriptions","organizations_url":"https://api.github.com/users/cisco/orgs","repos_url":"https://api.github.com/users/cisco/repos","events_url":"https://api.github.com/users/cisco/events{/privacy}","received_events_url":"https://api.github.com/users/cisco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cisco/libsrtp","description":"Library for SRTP (Secure Realtime Transport Protocol) ","fork":false,"url":"https://api.github.com/repos/cisco/libsrtp","forks_url":"https://api.github.com/repos/cisco/libsrtp/forks","keys_url":"https://api.github.com/repos/cisco/libsrtp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cisco/libsrtp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cisco/libsrtp/teams","hooks_url":"https://api.github.com/repos/cisco/libsrtp/hooks","issue_events_url":"https://api.github.com/repos/cisco/libsrtp/issues/events{/number}","events_url":"https://api.github.com/repos/cisco/libsrtp/events","assignees_url":"https://api.github.com/repos/cisco/libsrtp/assignees{/user}","branches_url":"https://api.github.com/repos/cisco/libsrtp/branches{/branch}","tags_url":"https://api.github.com/repos/cisco/libsrtp/tags","blobs_url":"https://api.github.com/repos/cisco/libsrtp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cisco/libsrtp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cisco/libsrtp/git/refs{/sha}","trees_url":"https://api.github.com/repos/cisco/libsrtp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cisco/libsrtp/statuses/{sha}","languages_url":"https://api.github.com/repos/cisco/libsrtp/languages","stargazers_url":"https://api.github.com/repos/cisco/libsrtp/stargazers","contributors_url":"https://api.github.com/repos/cisco/libsrtp/contributors","subscribers_url":"https://api.github.com/repos/cisco/libsrtp/subscribers","subscription_url":"https://api.github.com/repos/cisco/libsrtp/subscription","commits_url":"https://api.github.com/repos/cisco/libsrtp/commits{/sha}","git_commits_url":"https://api.github.com/repos/cisco/libsrtp/git/commits{/sha}","comments_url":"https://api.github.com/repos/cisco/libsrtp/comments{/number}","issue_comment_url":"https://api.github.com/repos/cisco/libsrtp/issues/comments{/number}","contents_url":"https://api.github.com/repos/cisco/libsrtp/contents/{+path}","compare_url":"https://api.github.com/repos/cisco/libsrtp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cisco/libsrtp/merges","archive_url":"https://api.github.com/repos/cisco/libsrtp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cisco/libsrtp/downloads","issues_url":"https://api.github.com/repos/cisco/libsrtp/issues{/number}","pulls_url":"https://api.github.com/repos/cisco/libsrtp/pulls{/number}","milestones_url":"https://api.github.com/repos/cisco/libsrtp/milestones{/number}","notifications_url":"https://api.github.com/repos/cisco/libsrtp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cisco/libsrtp/labels{/name}","releases_url":"https://api.github.com/repos/cisco/libsrtp/releases{/id}","deployments_url":"https://api.github.com/repos/cisco/libsrtp/deployments","created_at":"2013-03-28T22:08:25Z","updated_at":"2018-02-03T05:15:04Z","pushed_at":"2018-02-09T10:59:33Z","git_url":"git://github.com/cisco/libsrtp.git","ssh_url":"git@github.com:cisco/libsrtp.git","clone_url":"https://github.com/cisco/libsrtp.git","svn_url":"https://github.com/cisco/libsrtp","homepage":null,"size":5379,"stargazers_count":363,"watchers_count":363,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":196,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":196,"open_issues":15,"watchers":363,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/398"},"html":{"href":"https://github.com/cisco/libsrtp/pull/398"},"issue":{"href":"https://api.github.com/repos/cisco/libsrtp/issues/398"},"comments":{"href":"https://api.github.com/repos/cisco/libsrtp/issues/398/comments"},"review_comments":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/398/comments"},"review_comment":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cisco/libsrtp/pulls/398/commits"},"statuses":{"href":"https://api.github.com/repos/cisco/libsrtp/statuses/c995df45427efb149701548ea2d77a4d155b04e5"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"thisisG"}}