{"id":94335,"date":"2016-09-19T07:00:00","date_gmt":"2016-09-19T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=94335"},"modified":"2019-03-13T11:06:56","modified_gmt":"2019-03-13T18:06:56","slug":"20160919-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160919-00\/?p=94335","title":{"rendered":"It&#8217;s an unfortunate choice of data type for the file system redirection cookie"},"content":{"rendered":"<p>If you want to disable 64-bit file system redirection, you call the <code>Wow64&shy;Disable&shy;Wow64&shy;Fs&shy;Redirection<\/code> function. This function gives you a cookie. When you are finished, you call <code>Wow64&shy;Revert&shy;Wow64&shy;Fs&shy;Redirection<\/code>, passing the cookie you received from the previous call. Like this: <\/p>\n<pre>\nvoid* cookie;\nif (Wow64DisableWow64FsRedirection(&amp;cookie)) {\n   ... do stuff ...\n   Wow64RevertWow64FsRedirection(cookie);\n}\n<\/pre>\n<p>The unfortunate thing is that the data type for the cookie is an untyped pointer: <code>void*<\/code>. This means that the following mistake goes undetected: <\/p>\n<pre>\n<i>\/\/ Remember: Code in italics is wrong.\nvoid* cookie;\nif (Wow64DisableWow64FsRedirection(&amp;cookie)) {\n   ... do stuff ...\n   Wow64RevertWow64FsRedirection(&amp;cookie);\n}<\/i>\n<\/pre>\n<p>The erroneous parameter to <code>Wow64&shy;Revert&shy;Wow64&shy;Fs&shy;Redirection<\/code> goes undetected because <code>void**<\/code> is implicitly convertible to <code>void*<\/code>. Because <i>any pointer<\/i> is implicitly convertible to <code>void*<\/code>, because <code>void*<\/code> is a generic pointer. <\/p>\n<p>In retrospect, the type of the cookie used by the file system redirection functions should have been something other than <code>void*<\/code>. It could have used <code>DECLARE_HANDLE<\/code>, which declares a pointer to a dummy structure with a unique name. Or it could have been a pointer to a uniquely-named incomplete type. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The untyped pointer strikes again.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-94335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The untyped pointer strikes again.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=94335"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/94335\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=94335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=94335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=94335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}