{"id":266,"date":"2023-08-18T18:04:54","date_gmt":"2023-08-18T10:04:54","guid":{"rendered":"http:\/\/blog.xjfvps.top\/index.php\/2023\/08\/18\/curl%e9%81%87%e5%88%b0longjmp-causes-uninitialized-stack-frame%e7%9a%84%e5%a4%84%e7%90%86%e5%8a%9e%e6%b3%95\/"},"modified":"2023-08-18T21:31:05","modified_gmt":"2023-08-18T13:31:05","slug":"curl%e9%81%87%e5%88%b0longjmp-causes-uninitialized-stack-frame%e7%9a%84%e5%a4%84%e7%90%86%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.fs.cloudns.biz\/index.php\/2023\/08\/18\/curl%e9%81%87%e5%88%b0longjmp-causes-uninitialized-stack-frame%e7%9a%84%e5%a4%84%e7%90%86%e5%8a%9e%e6%b3%95\/","title":{"rendered":"curl\u9047\u5230longjmp causes uninitialized stack frame\u7684\u5904\u7406\u529e\u6cd5"},"content":{"rendered":"<p>\u6458\u81ea&nbsp;<a href=\"http:\/\/stackoverflow.com\/questions\/9191668\/error-longjmp-causes-uninitialized-stack-frame\">http:\/\/stackoverflow.com\/questions\/9191668\/error-longjmp-causes-uninitialized-stack-frame<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>I ran into the same issue; as noted above, it is a curl bug. I thought I would put an answer up here to pull together all of the available information on the problem.<\/p>\n<p>From&nbsp;<a href=\"https:\/\/bugzilla.redhat.com\/show_bug.cgi?id=539809\" rel=\"nofollow\">the Red Hat bug report<\/a>:<\/p>\n<blockquote>\n<p>libcurl built without an asynchronous resolver library uses alarm() to time out DNS lookups. When a timeout occurs, this causes libcurl to jump from the signal handler back into the library with a sigsetjmp, which effectively causes libcurl to continue running within the signal handler. This is non-portable and could cause problems on some platforms. A discussion on the problem is available at&nbsp;<a href=\"http:\/\/curl.haxx.se\/mail\/lib-2008-09\/0197.html\" rel=\"nofollow\">http:\/\/curl.haxx.se\/mail\/lib-2008-09\/0197.html<\/a><\/p>\n<\/blockquote>\n<p>The &#8220;problems on some platforms&#8221; apparently refers to crashes on modern Linux systems at least. Some deeper technical details are at the link from the quote above:<\/p>\n<blockquote>\n<p>There&#8217;s a problem with the way libcurl currently handles the SIGALRM signal. It installs a handler for SIGALRM to force a synchronous DNS resolve to time out after a specified time, which is the only way to abort such a resolve in some cases. Just before the the DNS resolve takes place it initializes a longjmp pointer so when the signal comes in the signal handler just does a siglongjmp, control continues from that saved location and the function returns an error code.<\/p>\n<p>The problem is that all the following control flow executes effectively inside the signal handler. Not only is there a risk that libcurl could call an async handler unsafe function (see signal(7)) during this time, but it could call a user callback function that could call absolutely anything. In fact, siglongjmp() itself is not on the POSIX list of async-safe functions, and that&#8217;s all the libcurl signal handler calls!<\/p>\n<\/blockquote>\n<p>There are a couple ways to solve this problem, depending upon whether you built libcurl or if you&#8217;re stuck with one that was provided by your distribution or system admin:<\/p>\n<ul>\n<li>\n<p>If you can&#8217;t rebuild libcurl, then you can call&nbsp;<code>curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1)<\/code>&nbsp;on all curl handles that you use. The documentation for&nbsp;<code>CURLOPT_NOSIGNAL<\/code>&nbsp;notes:<\/p>\n<blockquote>\n<p>Pass a long. If it is 1, libcurl will not use any functions that install signal handlers or any functions that cause signals to be sent to the process. This option is mainly here to allow multi-threaded unix applications to still set\/use all timeout options etc, without risking getting signals. (Added in 7.10)<\/p>\n<p><strong>If this option is set and libcurl has been built with the standard name resolver, timeouts will not occur while the name resolve takes place<\/strong>. Consider building libcurl with c-ares support to enable asynchronous DNS lookups, which enables nice timeouts for name resolves without signals.<\/p>\n<\/blockquote>\n<p>DNS timeouts are obviously desirable to have in most cases, so this isn&#8217;t a perfect fix. If you have the ability to rebuild libcurl on your system, then you can&#8230;<\/p>\n<\/li>\n<li>\n<p>There is an asynchronous DNS resolver library called&nbsp;<a href=\"http:\/\/c-ares.haxx.se\/\" rel=\"nofollow\">c-ares<\/a>&nbsp;that curl is capable of using for name resolution. Using this library is the preferred solution to the problem (and I would imagine most Linux packagers have figured this out by now). To enable c-ares support, first build and install the library, then pass the&nbsp;<code>--enable-ares<\/code>&nbsp;flag to curl&#8217;s&nbsp;<code>configure<\/code>&nbsp;script before you build.&nbsp;<a href=\"http:\/\/curl.haxx.se\/dev\/readme-ares.html\" rel=\"nofollow\">Full instructions are here<\/a>.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u81ea&nbsp;http:\/\/stackoverflow.com\/questio &hellip; <a href=\"https:\/\/blog.fs.cloudns.biz\/index.php\/2023\/08\/18\/curl%e9%81%87%e5%88%b0longjmp-causes-uninitialized-stack-frame%e7%9a%84%e5%a4%84%e7%90%86%e5%8a%9e%e6%b3%95\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,8,1],"tags":[21],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-linux","category-8","category-uncategorized","tag-linux"],"_links":{"self":[{"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":1,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":320,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions\/320"}],"wp:attachment":[{"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fs.cloudns.biz\/index.php\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}