{"id":1167,"date":"2015-05-07T17:40:19","date_gmt":"2015-05-07T15:40:19","guid":{"rendered":"http:\/\/blog.rewolf.pl\/blog\/?p=1167"},"modified":"2015-07-10T16:11:15","modified_gmt":"2015-07-10T14:11:15","slug":"resolving-vmware-workstation-10-0-6-crash","status":"publish","type":"post","link":"http:\/\/blog.rewolf.pl\/blog\/?p=1167","title":{"rendered":"Resolving VMware Workstation 10.0.6 crash"},"content":{"rendered":"<p style=\"text-align: justify;\">Two days ago <strong>VMware <\/strong>published new update for <strong>Workstation <\/strong>version <strong>10 <\/strong>(<a href=\"https:\/\/www.vmware.com\/support\/ws10\/doc\/workstation-1006-release-notes.html\" target=\"_blank\">release notes<\/a>). According to the changelog it should fix some security issues reported in <strong>OpenSSL<\/strong>. That&#8217;s nice, however there is a small problem with this update. VMware.exe (the GUI part of VMmare) started crashing immediately after update. This was quite a learning experience, do not update critical software if you have something important to do, as the new version can be worse than the one you are using. Since I didn&#8217;t have the previous installer at hand, I had to somehow resolve this issue differently (yeah sure, I just wanted to debug it and see, why it is crashing).<\/p>\n<p><!--more--><\/p>\n<p style=\"text-align: justify;\">The crash on my machine is 100% repeatable, and it crashes on security cookie check inside <strong>libcurl.dll<\/strong>. As most of you know <strong>libcurl <\/strong>is an open source library, so the bug should be hidden somewhere inside <strong>libcurl <\/strong>source code, or in the additional\/changed code that guys from VMware possibly touched. In the latter case, there should be available modified source code of the <strong>libcurl <\/strong>on the VMware page. It is not the case this time, so (in theory) it is fault of the <strong>libcurl <\/strong>itself. Crash happens inside the function that seems to enumerate DNS servers. <strong>Libcurl <\/strong>can be compiled with many different options and can use many different third party libraries. VMware&#8217;s <strong>libcurl <\/strong>version is compiled with static version of <strong>zlib <\/strong>and <strong><a href=\"http:\/\/c-ares.haxx.se\/\" target=\"_blank\">c-ares<\/a><\/strong>, it is also dynamically linked with <strong>OpenSSL<\/strong>. It is worth to note which versions of mentioned libraries are used. Most of open source libraries includes version number inside compiled binaries so it is rather easy to gather those information:<\/p>\n<table align=\"center\">\n<tr>\n<td><\/td>\n<td>VMWare 10.0.5<\/td>\n<td>VMWare 10.0.6<\/td>\n<td>Current version<\/td>\n<\/tr>\n<tr>\n<td>libcurl<\/td>\n<td>7.19.5<\/td>\n<td>7.24.0<\/td>\n<td>7.42.1<\/td>\n<\/tr>\n<tr>\n<td>zlib<\/td>\n<td>1.2.3<\/td>\n<td>1.2.3<\/td>\n<td>1.2.8<\/td>\n<\/tr>\n<tr>\n<td>c-ares<\/td>\n<td>1.5.1<\/td>\n<td>1.7.5<\/td>\n<td>1.10.0<\/td>\n<\/tr>\n<\/table>\n<p style=\"text-align: justify;\">Particulary interesting for me was <strong>libcurl <\/strong>and <strong>c-ares<\/strong>, as <strong>zlib <\/strong>probably doesn&#8217;t enumerate DNSes :) I&#8217;ve tried to localize the crashing function inside the source code of mentioned libs, but I was missing one detail (obviously!). In the newest version of <strong>c-ares<\/strong>, the function similar to the one that is crashing VMware is named <strong>get_DNS_NetworkParams()<\/strong>. This function doesn&#8217;t crash and it looks fine. After a few minutes of looking at the code and wondering what&#8217;s wrong I realized that I&#8217;ve freshly cloned <a href=\"http:\/\/github.com\/bagder\/c-ares\" target=\"_blank\">repository<\/a> with the latest changes and I should probably go back in time and check some older version. Fortunately <strong>c-ares<\/strong> repository is properly tagged with release version numbers (at least since version <strong>1.7.0<\/strong>). After checking out proper revision I&#8217;ve easily identified crashing function: <strong>get_iphlpapi_dns_info()<\/strong>. Simplified code, just to show the problem:<\/p>\n<pre lang=\"cpp\">#define INET_ADDRSTRLEN  22\r\n\r\nint get_iphlpapi_dns_info(char *ret_buf, size_t ret_size)\r\n{\r\n\tconst size_t  ipv4_size = INET_ADDRSTRLEN + 1;  \/* +1 for ',' at end *\/\r\n\tsize_t        left = ret_size;\r\n\tchar         *ret = ret_buf;\r\n\t\/\/...\r\n\tfor (\/*...*\/)\r\n\t{\r\n\t\t\/\/...\r\n\t\tif (left > ipv4_size)\r\n\t\t{\r\n\t\t\tsome_function_that_fills_given_buffer(ret, ipv4_size - 1);\r\n\t\t\tsize_t stringlen = strlen(ret);\r\n\t\t\tret[stringlen] = ',';\r\n\t\t\tret[stringlen + 1] = '\\0';\r\n\t\t\tret += stringlen + 1;\r\n\t\t\tleft -= ret - ret_buf;\t\/\/ <- !!! BUG BUG !!!\r\n\t\t}\r\n\t\t\/\/...\r\n\t}\r\n\t\/\/...\r\n}\r\n\r\n\/\/...\r\n\t\/\/ function call\r\n\tchar buf[512];\r\n\tget_iphlpapi_dns_info(buf,sizeof(buf));\r\n\/\/...\r\n<\/pre>\n<p style=\"text-align: justify;\">Variable <strong><em>left<\/em><\/strong> should be updated on each iteration with the length of the written data, so it will always contain number of bytes left in the <strong><em>ret_buf<\/em><\/strong>. As you may already noticed, <strong><em>ret_buf<\/em><\/strong> doesn't change throughout the function, so <strong><em>left<\/em><\/strong> is updated with the length of all strings written since the first iteration. It goes below 0 very fast and since it is declared as <strong>size_t<\/strong> which is unsigned it will be interpreted as such in the <strong><em>if (left > ipv4_size)<\/em><\/strong> comparison and at the end it will overrun <strong><em>ret_buf<\/em><\/strong> (only if there is enough records to process by the for loop).<\/p>\n<p style=\"text-align: justify;\">Described bug was present in <strong>c-ares<\/strong> library since the very begining (<a href=\"https:\/\/github.com\/bagder\/c-ares\/commit\/d37a866e8de8f5a5168de13210497bbf70e9c90f#diff-6c5528d5eccbe836842006e4f0cb89baR344\" target=\"_blank\">2004-06-10<\/a>). There were some changes regarding <strong>IPv6<\/strong> (<a href=\"https:\/\/github.com\/bagder\/c-ares\/commit\/6518b56a5e2bc9e39d720f17fa7dd322a28dc33c#diff-6c5528d5eccbe836842006e4f0cb89baR693\" target=\"_blank\">2011-05-17<\/a>) that were modifying this function, but bug persisted probably due to copy&paste from <strong>IPv4<\/strong> handler. Someone fixed this bug almost a year later (<a href=\"https:\/\/github.com\/bagder\/c-ares\/commit\/73dc26a9fc09fdce253a299a0144dc7ca6c10bf4\" target=\"_blank\">2012-02-25<\/a>) and the other person rewrote whole code few months later. Unfortunately VMware chose to use version <strong>1.7.5<\/strong> which was released before this bug was fixed (<a href=\"https:\/\/github.com\/bagder\/c-ares\/commit\/622313ab3b1c4ea96c3a9fa46081f4303720d7f4\" target=\"_blank\">2011-08-16<\/a>). Blast from the past.<\/p>\n<p style=\"text-align: justify;\"><strong>If you are experiencing crashes in VMware Workstation 10.0.6 just use libcurl.dll from the previous build, at least it will stop crashing.<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>UPDATE:<\/strong> Someone at <a href=\"https:\/\/communities.vmware.com\/message\/2505511#2505511\" target=\"_blank\">VMware forum<\/a> pointed out that it is sufficient to get <strong>libcurl.dll<\/strong> from the <strong>\\OVFTool\\<\/strong> directory and it will solve the issue. Indeed it is true, as <strong>libcurl<\/strong> from mentioned directory uses <strong>c-ares<\/strong> version <strong>1.9.1<\/strong> (<strong>libcurl<\/strong> itself is also newer as it has version <strong>7.30.0<\/strong>).<\/p>\n<p style=\"text-align: justify;\"><strong>UPDATE 2 (2015-07-10): <\/strong>This issue was fixed with v10.0.7, libcurl was updated to v7.32.0. I've also received free copy of VMware Workstation v11. Thanks!:<img decoding=\"async\" loading=\"lazy\" src=\"http:\/\/blog.rewolf.pl\/blog\/wp-content\/uploads\/2015\/05\/vmware_gift.png\" alt=\"vmware_gift\" width=\"420\" height=\"521\" class=\"aligncenter size-full wp-image-1401\" srcset=\"http:\/\/blog.rewolf.pl\/blog\/wp-content\/uploads\/2015\/05\/vmware_gift.png 420w, http:\/\/blog.rewolf.pl\/blog\/wp-content\/uploads\/2015\/05\/vmware_gift-242x300.png 242w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two days ago VMware published new update for Workstation version 10 (release notes). According to the changelog it should fix some security issues reported in OpenSSL. That&#8217;s nice, however there is a small problem with this update. VMware.exe (the GUI part of VMmare) started crashing immediately after update. This was quite a learning experience, do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10,3],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1167"}],"collection":[{"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1167"}],"version-history":[{"count":33,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1167\/revisions"}],"predecessor-version":[{"id":1402,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1167\/revisions\/1402"}],"wp:attachment":[{"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1167"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.rewolf.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}