标签: address-sanitizer

AddressSanitizer:DEADLYSIGNAL 尝试使用堆栈运行代码以获取有效括号问题集时出现 DEADLYSIGNAL 错误

我在 leetcode.com 上尝试这个名为“有效括号”的问题时,弹出了一条错误消息:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==30==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000003783d6 bp 0x7ffe68231e10 sp 0x7ffe68231ca0 T0)
==30==The signal is caused by a READ memory access.
==30==Hint: this fault was caused by a dereference of a high value address (see register values below).  Dissassemble the provided pc to learn which register was used.
    #3 0x7f427121b0b2  (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
AddressSanitizer can not provide additional info.
==30==ABORTING
Run Code Online (Sandbox Code Playgroud)

这是生成错误的代码

#include <stack>

using namespace std;

class Solution {
public:
    bool isValid(string str) {
        stack<char> s; …
Run Code Online (Sandbox Code Playgroud)

c++ segmentation-fault address-sanitizer

1
推荐指数
1
解决办法
2万
查看次数

结构体内部字符串的 malloc 溢出

以下代码是我目前正在处理的项目的示例,用 C 编码。

我首先 malloc 一个结构,然后作为例子 malloc 里面的第一个字符串。当我尝试将另一个字符串中的文本复制到其中并使用该printf函数打印它时,当我使用-fsanitize=addressas 编译标志进行编译时,它会溢出。

我不明白为什么,因为我认为我为字符串分配了足够的内存,因为我只是使用strlen另一个字符串的长度,为\0.

# include <stdio.h>
# include <stdlib.h>
# include <string.h>

typedef struct s_word
{
    int     length;
    char    *str;
}                       t_word;

typedef struct s_list
{
    t_word  *word;
}                       t_list;

int main(void)
{
    int     i;
    char    *line = "this is a test";
    t_list  test;

    i = -1;
    test.word = malloc(sizeof(t_word) * 10);
    test.word[0].str = malloc(sizeof(char) * (strlen(line) + 1));
    while (line[++i])
        test.word[0].str[i] = line[i];
    printf("%s\n", …
Run Code Online (Sandbox Code Playgroud)

c malloc struct address-sanitizer

1
推荐指数
1
解决办法
41
查看次数

为什么 ASAN 没有将其报告为 stack-use-after-scope 问题?

我无法理解 Address Sanitizer 背后的概念 - (stack-use-after-scope)。

#include <iostream>
using namespace std;
class User {
        public:
        User(){
                _name = "No Name";
        }
        User(string name){
                _name = name;
                _salary = 0;
        }

        string getName(){
                return _name;
        }

        int* getRoles(){
                return _roles;
        }
        private:
        string _name;
        int _salary;
        int _roles[5];
};

class Employee {
        public:
        Employee(User user){
                _user = user;
        }

        User getUser(){
                return _user;
        }
        private:
        User _user;

};
int main() {
        // your code goes here

        User user("User1");
        Employee employee(user);

        auto …
Run Code Online (Sandbox Code Playgroud)

c++ address-sanitizer

1
推荐指数
1
解决办法
96
查看次数

==44088==错误:AddressSanitizer:堆栈缓冲区溢出

我的项目是 swift-only(至少对于我写的代码)。在应用程序开始时,我下载了一些 json 来显示内容。我用swift 4 Coder protocol. 这已经工作了一段时间,但刚才我遇到了一个意外的堆栈缓冲区溢出错误:

==44088==ERROR: AddressSanitizer: stack-buffer-overflow

在后台线程之一中反序列化其中一个对象时。

基于此,我有两个问题

我怎样才能确保这种情况不再发生?

有没有办法重现它?

更多信息:

我有这个摘要,但我不知道该怎么做:

SUMMARY: AddressSanitizer: stack-buffer-overflow JsonClass.swift in _T06MyApp11JsonClassVACs7Decoder_p4from_tKcfC Shadow bytes around the buggy address: 0x100026a904d0: 00 02 f2 f2 f2 f2 f2 f2 f2 f2 00 00 00 00 00 00 0x100026a904e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x100026a904f0: 00 00 00 00 00 00 00 00 00 00 00 00 …

ios address-sanitizer swift

0
推荐指数
1
解决办法
7784
查看次数

Asan:asan 库加载问题

在我们的构建系统中,我们最近将 ASAN 工具(添加 -fsanitize=address)集成到 CFLAGS 中,同时也在链接、创建库 .so 文件的同时。注意:- 我们使用 GCC 6.3 编译器。

我们能够成功构建我们的代码。但是在运行时失败并出现以下问题:

==52215==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
Run Code Online (Sandbox Code Playgroud)

这是我的 gcc 命令:-

/local/common/pkgs/gcc/v6.3.0/bin/gcc -m32 -shared -o /local/testing/build/new_tool/asan_build/syn/verilog/libspd.so  -Wl,-rpath=\$ORIGIN/lib -Wl,-rpath=\$ORIGIN/../lib -W1,-rpath=/local/common/gcc/v6.3.0/lib  -fsanitize=address -L/local/testing/build/new_tool/asan_build/modules /local/testing/build/new_tool/asan_build/modules/silvpi.o /local/testing/build/new_tool/asan_build/modules/sypsv.o /local/testing/build/new_tool/asan_build/modules/cdnsv_tfs.o /local/testing/build/new_tool/asan_build/modules/libcore.o /local/testing/build/new_tool/asan_build/modules/vpi_user.o /local/testing/build/new_tool/asan_build/modules/libdenbase.a /local/testing/build/new_tool/asan_build/modules/libbdd.a  -L/local/testing/build/new_tool/asan_build/syn/lib -L/local/testing/build/new_tool/asan_build/modules -L/home/local/outer/Linux/lib /local/testing/build/new_tool/asan_build/modules/vhpimodelfunc.o /local/testing/build/new_tool/asan_build/modules/vipcommonlib.a  -lm -lc -ldenbase -lbdd -ldenbase -lviputil -llocalCommonMT_sh
Run Code Online (Sandbox Code Playgroud)

我能够libspd.so成功构建库。但是当我们尝试运行它时,它会因我提到的上述错误而失败。

我可以看到依赖库列表 libspd.so

ldd /local/testing/build/new_tool/asan_build/syn/verilog/libspd.so
    linux-gate.so.1 =>  (0x00279000)
    libasan.so.3 …
Run Code Online (Sandbox Code Playgroud)

gcc gnu-make address-sanitizer

0
推荐指数
1
解决办法
6624
查看次数

无法在 XCode 12 中链接地址清理程序

我正在尝试使用 asan 在 xcode 中构建 C++ 项目。在链接步骤构建失败并出现错误:

Undefined symbol: ___asan_version_mismatch_check_apple_clang_1200
Run Code Online (Sandbox Code Playgroud)

我选中了“产品>方案>编辑方案>地址消毒剂”中的框,并在“其他链接选项”中添加了链接器标志:“-fsanitize=address”。

从日志中我可以看到它使用 -fsanitize=address 标志运行 ld 命令。

然而,经过所有这些步骤,它仍然不起作用。如何解决这个问题呢?

c++ xcode address-sanitizer

0
推荐指数
1
解决办法
471
查看次数

使用指针并且没有使用`free()`并且没有内存泄漏

在我的程序中,我使用了malloc()和 指针,但我没有用来free()释放这些内存,我已经使用-fsanitize=address标志进行了编译,但它说没有内存泄漏。据我所知,如果我分配内存,我还必须在程序结束时释放内存,否则会出现内存泄漏。

#include <stdio.h>
#include <stdlib.h>


void print2D(int rowSize, int **cols_size, int **arr) {

    for(int i = 0; i < rowSize; i++) {
        for(int j = 0; j < (*cols_size)[i]; j++) {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }
}

int** make2D(int rowSize, int **colSize) {

    int** arr = (int**) malloc(sizeof(int*) * rowSize);

    for(int i=0; i < rowSize; i++) {
        arr[i] = (int*) malloc(sizeof(int) * 2);
    }

    *colSize = (int*) malloc(sizeof(int*) * 2);

    (*colSize)[0] = …
Run Code Online (Sandbox Code Playgroud)

c malloc free gcc address-sanitizer

0
推荐指数
1
解决办法
273
查看次数

地址清理程序未找到丢失的删除语句

我已在 Visual Studio 中为我的项目启用了 Address Sanitizer,并成功使用Microsoft Learn中的以下代码对其进行了测试。

#include <stdio.h>

int x[100];

int main() {
    printf("Hello!\n");
    x[100] = 5; // Boom!
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,清理程序无法在以下代码中找到丢失的删除语句:

struct Object {
    int x;
    int y;
};

int main() {
    Object* obj = new Object();
    // Boom!
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

查看生成的程序集,我们可以看到 new 运算符确实被调用并且没有被优化掉。以下输出取自 Debug/x86 配置,但对于配置 Debug/x64、Release/x86 和 Release/x64 可以获得类似的输出。

; 6    : int main() {

    push    ebp
    mov ebp, esp
    sub esp, 12                 ; 0000000cH
    mov ecx, OFFSET __62A33F1D_Source@cpp
    call    @__CheckForDebuggerJustMyCode@4

; 7    : …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ address-sanitizer visual-studio-2022

0
推荐指数
1
解决办法
273
查看次数

如果我将 vector&lt;int&gt; 添加到用于通过 new[] 创建数组的类中,为什么会出现内存泄漏

我写了这段代码:

#include <iostream>
#include <memory>
using namespace std;

class G {
public:
    vector<int> v = {1};
};

int main() {
    G* t = new G[5];
    new (t) G();
    delete [] t;
}
Run Code Online (Sandbox Code Playgroud)

我通过这种方式编译:

clang++ -std=c++20 -fsanitize=address b.cpp -o main -Werror && ./main
Run Code Online (Sandbox Code Playgroud)

sanitizer 检测到内存泄漏,4 字节,因为我将向量 v = {1} 添加到 G 类。没有这个向量它可以正常工作。请告诉我问题是什么,我不明白。

我预计该代码会正常工作。我预计向量 v 将被标准析构函数破坏。

c++ memory-leaks vector address-sanitizer

0
推荐指数
1
解决办法
88
查看次数