首页 > 其他分享 >Address Sanitizer安装和使用

Address Sanitizer安装和使用

时间:2024-03-12 17:35:03浏览次数:24  
标签:redzone 00 Sanitizer fa fd 内存 Address main 安装


参考

https://www.cnblogs.com/gscnblog/p/15612349.html

https://github.com/google/sanitizers/wiki/AddressSanitizer

由于 C/C++ 这类编程语言与硬件(主要是内存)非常贴近,使用 C/C++ 编程,经常遇到的的一个问题就是内存错误,其中可能包括:

  1. 内存泄漏:忘记 free 之前在堆中申请的内存,并丢失了所申请内存的指针;
  2. 内存访问越界:包括对全局内存、栈内存、堆内存访问的越界;
  3. 释放后使用:访问已经被 free 的内存;
  4. 返回后使用:访问已经返回的函数栈中的内

 

版本升级到GCC 4.9以上

sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get install g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 10

实例代码:

#include <stdlib.h>

int main() {
  char *x = (char*)malloc(10 * sizeof(char*));
  free(x);
  return x[5];
}

g++ -fsanitize=address  -g main.cpp  

./a.out

=================================================================
==14326==ERROR: AddressSanitizer: heap-use-after-free on address 0x607000000095 at pc 0x562e0085aa54 bp 0x7ffe25ae8bd0 sp 0x7ffe25ae8bc0
READ of size 1 at 0x607000000095 thread T0
#0 0x562e0085aa53 in main /data/backup/test_sanitizer/main.cpp:10
#1 0x7f5e67656c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)
#2 0x562e0085a909 in _start (/data/backup/test_sanitizer/a.out+0x909)

0x607000000095 is located 5 bytes inside of 80-byte region [0x607000000090,0x6070000000e0)
freed by thread T0 here:
#0 0x7f5e67b047a8 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xde7a8)
#1 0x562e0085aa0b in main /data/backup/test_sanitizer/main.cpp:8
#2 0x7f5e67656c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

previously allocated by thread T0 here:
#0 0x7f5e67b04b40 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb40)
#1 0x562e0085a9fb in main /data/backup/test_sanitizer/main.cpp:7
#2 0x7f5e67656c86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c86)

SUMMARY: AddressSanitizer: heap-use-after-free /data/backup/test_sanitizer/main.cpp:10 in main
Shadow bytes around the buggy address:
0x0c0e7fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0e7fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0e7fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0e7fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c0e7fff8000: fa fa fa fa 00 00 00 00 00 00 00 00 00 fa fa fa
=>0x0c0e7fff8010: fa fa[fd]fd fd fd fd fd fd fd fd fd fa fa fa fa
0x0c0e7fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0e7fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0e7fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0e7fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c0e7fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==14326==ABORTING

 

标签:redzone,00,Sanitizer,fa,fd,内存,Address,main,安装
From: https://www.cnblogs.com/7star/p/18068821

相关文章

  • Linux安装Redis
    1.使用命令下载wgethttp://download.redis.io/releases/redis-5.0.7.tar.gz2.将压缩包复制移动到/opt目录下mvredis-5.0.7.tar.gz/opt3.进入到/opt目录下cd/opt/4.解压tar-zxvfredis-5.0.7.tar.gz5.进入到解压后的文件,可以看见redis的配置文件6.安装基本的运行环......
  • CentOS 安装 Docker Compose(curl 方式)
    CentOS安装DockerCompose(curl方式)下载运行此命令下载最新版本的DockerCompose:sudocurl-Lhttps://github.com/docker/compose/releases/download/v2.20.0/docker-compose-`uname-s`-`uname-m`-o/usr/local/bin/docker-composedocker-compose2.20.0Linux64位版......
  • CentOS 安装 Docker(yum)
    CentOS安装Docker(yum)查看已经安装的dockeryumlistinstalled|grepdocker卸载已经安装的dockeryum-yremovedocker-ce.x86_64安装存储库sudoyuminstall-yyum-utilsdevice-mapper-persistent-datalvm2yum-utils提供了yum-config-manager效用,并device-mapper......
  • mysqld_exporter的安装
    1.需要在数据库上创建对应用户及权限createuser'mysql_monitor'@'%'IDENTIFIEDBY'mysql_monitor';GRANTREPLICATIONCLIENT,PROCESS,SELECTON*.*TO'mysql_monitor'@'%'IDENTIFIEDBY'mysql_monitor';FLUSHPRIV......
  • win10在任意位置安装Linux子系统
    1.把WSL1设置为默认版本以管理员身份打开Powershell,输入命令wsl--set-default-version12.启用适用于Linux的Windows子系统控制面板--程序--程序和功能--启用或关闭Windows功能选中适用于Linux的Windows子系统,确定完成后重启生效3.下载WSLLinux手动安装包选择Linux版本,下载......
  • CentOS8安装postgresql13和postgis
    CentOS8安装postgresql13和postgis这里使用的是8.5.2111操作系统版本,首先解决一下网络源的问题。检验dnf是否能正常使用,顺便安装wgetdnf-yinstallwget 一、安装postgresql131、配置postgresql官网提供的网络源dnfinstall-yhttps://download.postgre......
  • 如何在Anolis 8 安装 极狐GitLab Runner
    GitLab是一个全球知名的一体化DevOps平台,很多人都通过私有化部署GitLab来进行源代码托管。极狐GitLab是GitLab在中国的发行版,专门为中国程序员服务。可以一键式部署极狐GitLab。基于Anolis龙蜥8和极狐GitLab官方仓库脚本安装/配置极狐GitLabRunner说明我们先......
  • 虚拟机安装麒麟银河操作系统(Kylin Linux Advanced Server V10)以及设置网卡信息
    1、下载银河麒麟操作系统镜像https://distro-images.kylinos.cn:8802/web_pungi/download/share/Dq5r12WhYyFwAcnZP4JeGXkbsEHOBM0N/Kylin-Server-V10-SP3-General-Release-2303-X86_64.iso2、设置vm       #磁盘建议给到40G #点击完成开始下一步安装和......
  • Windows10 windows installer卸载或安装不了软件怎么办?
        先说我的方法:      1.把安装出现问题的软件或者想要卸载的软件的安装目录下的所有文件都删除。      2.用清理软件清理一下垃圾,包括注册表,这里我自己使用的是火绒->安全工具->系统工具->垃圾清理。      3.手动卸载目标软件,这里我是直接去控......
  • macOS 下使用 pyenv 安装 python 2.n.p 报错,ERROR: The Python zlib extension was no
    TL;DR执行brewinstallzlib安装zlib之后,根据安装信息提示将一下三行变量exportLDFLAGS="-L/opt/homebrew/opt/zlib/lib"exportCPPFLAGS="-I/opt/homebrew/opt/zlib/include"exportPKG_CONFIG_PATH="/opt/homebrew/opt/zlib/lib/pkgconfig"加入到~/.zsh......