需要 Valgrind 输出解释协助
Valgrind output interpretation assistance needed
我是 C 编程的新手,有人要求我检查 linux 实用程序是否存在缓冲区溢出,但是我对这方面的了解有限,所以请原谅我做得不好在它。我使用 Valgrind 来检测溢出,并且在其中我收到了一个明确的泄漏,所以我应用了 --leak-check-full 来确定泄漏可能来自哪里,但是我'我不确定我该如何进行,有人可以帮助我吗?
我选择的实用程序是 nstat。这是我的结果:
valgrind --leak-check=full nstat -d 1111111111
==3749== Memcheck, a memory error detector
==3749== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3749== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==3749== Command: nstat -d 1111111111
==3749==
#kernel
IpInReceives 112 0.0
IpInDelivers 112 0.0
IpOutRequests 115 0.0
TcpActiveOpens 6 0.0
TcpInSegs 30 0.0
TcpOutSegs 32 0.0
TcpRetransSegs 1 0.0
UdpInDatagrams 82 0.0
UdpOutDatagrams 82 0.0
Ip6InReceives 2 0.0
Ip6InDelivers 2 0.0
Ip6OutRequests 2 0.0
Ip6OutNoRoutes 2 0.0
Ip6InMcastPkts 2 0.0
Ip6OutMcastPkts 2 0.0
Ip6InOctets 186 0.0
Ip6OutOctets 186 0.0
Ip6InMcastOctets 186 0.0
Ip6OutMcastOctets 186 0.0
Ip6InNoECTPkts 2 0.0
Udp6InDatagrams 2 0.0
Udp6OutDatagrams 2 0.0
TcpExtTW 2 0.0
TcpExtTCPHPHits 6 0.0
TcpExtTCPPureAcks 5 0.0
TcpExtTCPHPAcks 6 0.0
TcpExtTCPTimeouts 1 0.0
TcpExtTCPSynRetrans 1 0.0
TcpExtTCPOrigDataSent 12 0.0
TcpExtTCPDelivered 18 0.0
IpExtInMcastPkts 4 0.0
IpExtOutMcastPkts 4 0.0
IpExtInOctets 10138 0.0
IpExtOutOctets 9060 0.0
IpExtInMcastOctets 292 0.0
IpExtOutMcastOctets 292 0.0
IpExtInNoECTPkts 112 0.0
==3749==
==3749== HEAP SUMMARY:
==3749== in use at exit: 18,429 bytes in 725 blocks
==3749== total heap usage: 756 allocs, 31 frees, 34,350 bytes allocated
==3749==
==3749== 128 bytes in 1 blocks are definitely lost in loss record 1 of 9
==3749== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==3749== by 0x10C79D: ??? (in /usr/bin/nstat)
==3749== by 0x4BE00B2: (below main) (libc-start.c:308)
==3749==
==3749== LEAK SUMMARY:
==3749== definitely lost: 128 bytes in 1 blocks
==3749== indirectly lost: 0 bytes in 0 blocks
==3749== possibly lost: 0 bytes in 0 blocks
==3749== still reachable: 18,301 bytes in 724 blocks
==3749== suppressed: 0 bytes in 0 blocks
==3749== Reachable blocks (those to which a pointer was found) are not shown.
==3749== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3749==
==3749== For lists of detected and suppressed errors, rerun with: -s
==3749== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
我在 Valgrind 手册上搜索过类似的输出结果,但没有找到。如果有人能告诉我如何继续我的分析,那就太好了。
如果您正在检查缓冲区溢出,请放心,泄漏不属于该类别。但是,您的工作还远未完成。您需要考虑两个主要项目。
首先是您的代码覆盖率。仅仅一项测试可能远远不够。理想情况下,您应该有一个完整的测试套件,其中还包含测试覆盖率的度量。
其次,哪个工具最好。 Valgrind memcheck 而不是 做的一件事是检查静态分配变量和全局变量的溢出。动态分配的内存(使用 malloc 或 new)将 检查。
为了检查静态分配和全局变量,我建议您使用地址清理器。但是,这将需要重建 nstat
.
我是 C 编程的新手,有人要求我检查 linux 实用程序是否存在缓冲区溢出,但是我对这方面的了解有限,所以请原谅我做得不好在它。我使用 Valgrind 来检测溢出,并且在其中我收到了一个明确的泄漏,所以我应用了 --leak-check-full 来确定泄漏可能来自哪里,但是我'我不确定我该如何进行,有人可以帮助我吗?
我选择的实用程序是 nstat。这是我的结果:
valgrind --leak-check=full nstat -d 1111111111
==3749== Memcheck, a memory error detector
==3749== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3749== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==3749== Command: nstat -d 1111111111
==3749==
#kernel
IpInReceives 112 0.0
IpInDelivers 112 0.0
IpOutRequests 115 0.0
TcpActiveOpens 6 0.0
TcpInSegs 30 0.0
TcpOutSegs 32 0.0
TcpRetransSegs 1 0.0
UdpInDatagrams 82 0.0
UdpOutDatagrams 82 0.0
Ip6InReceives 2 0.0
Ip6InDelivers 2 0.0
Ip6OutRequests 2 0.0
Ip6OutNoRoutes 2 0.0
Ip6InMcastPkts 2 0.0
Ip6OutMcastPkts 2 0.0
Ip6InOctets 186 0.0
Ip6OutOctets 186 0.0
Ip6InMcastOctets 186 0.0
Ip6OutMcastOctets 186 0.0
Ip6InNoECTPkts 2 0.0
Udp6InDatagrams 2 0.0
Udp6OutDatagrams 2 0.0
TcpExtTW 2 0.0
TcpExtTCPHPHits 6 0.0
TcpExtTCPPureAcks 5 0.0
TcpExtTCPHPAcks 6 0.0
TcpExtTCPTimeouts 1 0.0
TcpExtTCPSynRetrans 1 0.0
TcpExtTCPOrigDataSent 12 0.0
TcpExtTCPDelivered 18 0.0
IpExtInMcastPkts 4 0.0
IpExtOutMcastPkts 4 0.0
IpExtInOctets 10138 0.0
IpExtOutOctets 9060 0.0
IpExtInMcastOctets 292 0.0
IpExtOutMcastOctets 292 0.0
IpExtInNoECTPkts 112 0.0
==3749==
==3749== HEAP SUMMARY:
==3749== in use at exit: 18,429 bytes in 725 blocks
==3749== total heap usage: 756 allocs, 31 frees, 34,350 bytes allocated
==3749==
==3749== 128 bytes in 1 blocks are definitely lost in loss record 1 of 9
==3749== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==3749== by 0x10C79D: ??? (in /usr/bin/nstat)
==3749== by 0x4BE00B2: (below main) (libc-start.c:308)
==3749==
==3749== LEAK SUMMARY:
==3749== definitely lost: 128 bytes in 1 blocks
==3749== indirectly lost: 0 bytes in 0 blocks
==3749== possibly lost: 0 bytes in 0 blocks
==3749== still reachable: 18,301 bytes in 724 blocks
==3749== suppressed: 0 bytes in 0 blocks
==3749== Reachable blocks (those to which a pointer was found) are not shown.
==3749== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3749==
==3749== For lists of detected and suppressed errors, rerun with: -s
==3749== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
我在 Valgrind 手册上搜索过类似的输出结果,但没有找到。如果有人能告诉我如何继续我的分析,那就太好了。
如果您正在检查缓冲区溢出,请放心,泄漏不属于该类别。但是,您的工作还远未完成。您需要考虑两个主要项目。
首先是您的代码覆盖率。仅仅一项测试可能远远不够。理想情况下,您应该有一个完整的测试套件,其中还包含测试覆盖率的度量。
其次,哪个工具最好。 Valgrind memcheck 而不是 做的一件事是检查静态分配变量和全局变量的溢出。动态分配的内存(使用 malloc 或 new)将 检查。
为了检查静态分配和全局变量,我建议您使用地址清理器。但是,这将需要重建 nstat
.