LouisBrunner / valgrind-macos

A valgrind mirror with latest macOS support
GNU General Public License v2.0
1.13k stars 58 forks source link

Valgrind crashes with libcurl on macos 10.15.4 catalina #14

Closed hanayashiki closed 3 years ago

hanayashiki commented 4 years ago

Source code:

/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.haxx.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ***************************************************************************/
/* <DESC>
 * Very simple HTTP GET
 * </DESC>
 */
#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
        /* example.com is redirected, so we tell libcurl to follow redirection */
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));

        /* always cleanup */
        curl_easy_cleanup(curl);
    }
    return 0;
}

libcurl version:

curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2
Release-Date: 2019-03-27

macos version:

image

output

/usr/local/bin/valgrind --tool=memcheck --xml=yes --xml-file=/private/var/folders/q2/mwnbkl7567d4yckmth3g3g440000gn/T/valgrind --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no /Users/(omiited)
--90163-- run: /usr/bin/dsymutil "(omiited)"

valgrind: m_syswrap/syswrap-darwin.c:8516 (void vgSysWrap_darwin_mach_msg_before(ThreadId, SyscallArgLayout *, SyscallArgs *, SyscallStatus *, UWord *)): Assertion 'trailer->msgh_trailer_type == MACH_MSG_TRAILER_FORMAT_0' failed.

host stacktrace:
==90163==    at 0x258042CFF: ???
==90163==    by 0x258043075: ???
==90163==    by 0x258043058: ???
==90163==    by 0x2580DD24B: ???
==90163==    by 0x2580B9913: ???
==90163==    by 0x2580B829A: ???
==90163==    by 0x2580B6229: ???
==90163==    by 0x2580C7341: ???
==90163==    by 0x2580C75E9: ???

sched status:
  running_tid=2

Thread 1: status = VgTs_WaitSys syscall unix:93 (lwpid 771)
client stack range: [0x10410A000 0x104909FFF] client SP: 0x104909658
valgrind stack range: [0x7000069AE000 0x700006AADFFF] top usage: 10480 of 1048576

Thread 2: status = VgTs_Runnable syscall mach:31 (lwpid 3331)
client stack range: [0x70000B6DA000 0x70000B759FFF] client SP: 0x70000B759898
valgrind stack range: [0x700009ACA000 0x700009BC9FFF] top usage: 4512 of 1048576

Note: see also the FAQ in the source distribution.
It contains workarounds to several common problems.
In particular, if Valgrind aborted or crashed after
identifying problems in your program, there's a good chance
that fixing those problems will prevent Valgrind aborting or
crashing, especially if it happened in m_mallocfree.c.

If that doesn't help, please report this bug to: www.valgrind.org

In the bug report, send all the above text, the valgrind
version, and what OS and version you are using.  Thanks.

valgrind version

3.17.0.GIT
hanayashiki commented 4 years ago

Does this also happen on other platforms?

LouisBrunner commented 4 years ago

Hi @hanayashiki,

You seem to be running in the same issue as #13, which is one of my attempts to fix a warning in valgrind that backfired. I will try to get it fixed soon.

hanayashiki commented 4 years ago

Hi @hanayashiki,

You seem to be running in the same issue as #13, which is one of my attempts to fix a warning in valgrind that backfired. I will try to get it fixed soon.

thank you!

LouisBrunner commented 4 years ago

I reverted some checks to be internal warnings again, you might want to give it a try again?

hanayashiki commented 4 years ago

I reverted some checks to be internal warnings again, you might want to give it a try again?

I uninstalled and reinstalled valgrind using the cmd given in your readme. There are still errors but different. The output from the same code:

/usr/local/bin/valgrind --tool=memcheck --xml=yes --xml-file=/private/var/folders/q2/mwnbkl7567d4yckmth3g3g440000gn/T/valgrind --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no (...)
--30605-- run: /usr/bin/dsymutil "(...)"
--30605-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--30605-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--30605-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--30605-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
--30605-- WARNING: unhandled amd64-darwin syscall: unix:501
--30605-- You may be able to write your own handler.
--30605-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--30605-- Nevertheless we consider this a bug.  Please report
--30605-- it at http://valgrind.org/support/bug_reports.html.
--30605-- WARNING: unhandled amd64-darwin syscall: unix:501
--30605-- You may be able to write your own handler.
--30605-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--30605-- Nevertheless we consider this a bug.  Please report
--30605-- it at http://valgrind.org/support/bug_reports.html.
UNKNOWN workq_ops option 1024
--30605-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 16 times)
==30605==  If you believe this happened as a result of a stack
==30605==  overflow in your program's main thread (unlikely but
==30605==  possible), you can try to increase the size of the
==30605==  main thread stack using the --main-stacksize= flag.
==30605==  The main thread stack size used in this run was 8388608.
--30605:0:schedule VG_(sema_down): read returned -4
LouisBrunner commented 4 years ago

Ok, so it's just a missing syscall, that should be easy enough to add, I'll keep you up to date.

LouisBrunner commented 4 years ago

@hanayashiki I am working through it now, however it looks like it's not crashing anymore?

hanayashiki commented 4 years ago

I hope I was reinstalling in the correct way, but the error persists.

--10946-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--10946-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--10946-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--10946-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
--10946-- WARNING: unhandled amd64-darwin syscall: unix:501
--10946-- You may be able to write your own handler.
--10946-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--10946-- Nevertheless we consider this a bug.  Please report
--10946-- it at http://valgrind.org/support/bug_reports.html.
--10946-- WARNING: unhandled amd64-darwin syscall: unix:501
--10946-- You may be able to write your own handler.
--10946-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--10946-- Nevertheless we consider this a bug.  Please report
--10946-- it at http://valgrind.org/support/bug_reports.html.
UNKNOWN workq_ops option 1024
--10946-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 16 times)
==10946==  If you believe this happened as a result of a stack
==10946==  overflow in your program's main thread (unlikely but
==10946==  possible), you can try to increase the size of the
==10946==  main thread stack using the --main-stacksize= flag.
==10946==  The main thread stack size used in this run was 8388608.
--10946:0:schedule VG_(sema_down): read returned -4

This is the log of reinstalling:

 brew install --HEAD https://raw.githubusercontent.com/LouisBrunner/valgrind-macos/master/valgrind.rb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/cask and homebrew/services).
==> New Formulae
fetch                                   shallow-backup                          torchvision
==> Updated Formulae
Updated 73 formulae.
==> Updated Casks
activedock                              goland                                  signal
alt-tab                                 graphicconverter                        sipgate-softphone
amazon-chime                            hydrogen                                snagit
anydesk                                 i1profiler                              soundsource
anydo                                   integrity                               taskade
appcode                                 kafka-tool                              texpad
appgate-sdp-client                      libreoffice                             ticktick
axe-edit-iii                            libreoffice-language-pack               tidepool-uploader
axure-rp                                loom                                    timing
backuploupe                             macintoshjs                             trader-workstation
balsamiq-wireframes                     melodics                                tuple
bitwarden                               mendeley-reference-manager              ultimate
blender                                 middle                                  unnaturalscrollwheels
blitz                                   milanote                                vivaldi
blocs                                   mochi                                   voov-meeting
buildsettingextractor                   navicat-premium                         wasabi-wallet
camtasia                                neo4j                                   wechatwork
cctalk                                  path-finder                             windows95
chef-workstation                        pdf-expert                              wire
chronicle                               permute                                 wondershare-uniconverter
copyclip                                phocus                                  wordpresscom
deepl                                   pinta                                   workflowy
downie                                  protonvpn                               yinxiangbiji
electerm                                qfinder-pro                             ytmdesktop-youtube-music
element                                 qownnotes                               yyets
engine-prime                            qv2ray                                  zoc
get-backup-pro                          sameboy                                 zoom-for-it-admins
gitkraken                               screaming-frog-seo-spider               zoomus
glyphs                                  segger-embedded-studio-for-arm

Warning: Calling Non-checksummed download of valgrind formula file from an arbitrary URL is deprecated! Use 'brew extract' or 'brew create' and 'brew tap-new' to create a formula file in a tap on GitHub instead.
######################################################################## 100.0%
==> Cloning https://github.com/LouisBrunner/valgrind-macos.git
Updating /Users/chenyuwang/Library/Caches/Homebrew/valgrind--git
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
HEAD is now at e0af3eb59 Merge branch 'development'
==> ./autogen.sh
==> ./configure --prefix=/usr/local/Cellar/valgrind/HEAD-e0af3eb --enable-only64bit --build=amd64-darwin
==> make
==> make install
🍺  /usr/local/Cellar/valgrind/HEAD-e0af3eb: 291 files, 31.3MB, built in 1 minute 25 seconds

I think you might try to valgrind the code given by me for a more timely debugging?

LouisBrunner commented 4 years ago

Oh sorry, I meant that when I was trying your code, I could see warnings but it wouldn't crash. Annoying, but still functional.

In any case, I have actually implemented these syscalls last month but didn't get around to release them. I have now pushed it on master so you should be able to upgrade valgrind and it should work without issues.

hanayashiki commented 4 years ago

I reinstalled my valgrind to the latest version, there's another error

/usr/local/bin/valgrind --tool=memcheck --xml=yes --xml-file=/private/var/folders/q2/mwnbkl7567d4yckmth3g3g440000gn/T/valgrind --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no ....
--35506-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
--35506-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 2 times)
--35506-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 4 times)
--35506-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 8 times)
UNKNOWN workq_ops option 1024
--35506-- UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option (repeated 16 times)
==35506==  If you believe this happened as a result of a stack
==35506==  overflow in your program's main thread (unlikely but
==35506==  possible), you can try to increase the size of the
==35506==  main thread stack using the --main-stacksize= flag.
==35506==  The main thread stack size used in this run was 8388608.
--35506:0:schedule VG_(sema_down): read returned -4

Process finished with exit code 11
LouisBrunner commented 4 years ago

I just tested it on my computer using macOS 10.15.6 and Xcode 10.15.6 and it works without crashing. What is the exact command line arguments you are using?

LouisBrunner commented 3 years ago

Feel free to reopen if you have a command which can trigger this bug