diff --git a/.travis.yml b/.travis.yml index e8daf5d613..b1cbd344ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,7 +60,7 @@ jobs: # ASAN as a best effort on every push - if: (not head_branch =~ ^release-* AND not head_branch =~ ^prerelease-* AND not branch =~ ^release-* AND not branch =~ ^prerelease-*) AND (head_branch =~ ^asan-* OR type = push) os: linux - env: COMPILER_NAME=clang CXX=clang++ CC=clang ASAN=1 ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=detect_leaks=0 CFLAGS="-DR2_ASSERT_STDOUT=1" + env: COMPILER_NAME=gcc INSTALL_SYSTEM=meson ASAN=1 ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=detect_leaks=0 CFLAGS="-DR2_ASSERT_STDOUT=1" # release-only: meson build with system libraries - if: head_branch =~ ^release-* OR head_branch =~ ^prerelease-* OR branch =~ ^release-* OR branch =~ ^prerelease-* os: linux @@ -68,7 +68,7 @@ jobs: # release-only: meson build with ASAN and R2_ASSERT_STDOUT - if: head_branch =~ ^release-* OR head_branch =~ ^prerelease-* OR branch =~ ^release-* OR branch =~ ^prerelease-* os: linux - env: COMPILER_NAME=clang CXX=clang++ CC=clang CFLAGS="-DR2_ASSERT_STDOUT=1" ASAN=1 ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=detect_leaks=0 RELEASE=1 + env: COMPILER_NAME=gcc CFLAGS="-DR2_ASSERT_STDOUT=1" INSTALL_SYSTEM=meson ASAN=1 ASAN_OPTIONS=detect_odr_violation=0 LSAN_OPTIONS=detect_leaks=0 RELEASE=1 # release-only: nogpl plugins file, just test if it builds - if: head_branch =~ ^release-* OR head_branch =~ ^prerelease-* OR branch =~ ^release-* OR branch =~ ^prerelease-* os: linux diff --git a/libr/anal/cc.c b/libr/anal/cc.c index a1a05c9b23..ccad64640e 100644 --- a/libr/anal/cc.c +++ b/libr/anal/cc.c @@ -100,10 +100,12 @@ R_API bool r_anal_cc_exist(RAnal *anal, const char *convention) { } R_API const char *r_anal_cc_arg(RAnal *anal, const char *convention, int n) { - r_return_val_if_fail (anal && convention, NULL); - if (n < 0) { + r_return_val_if_fail (anal, NULL); + r_return_val_if_fail (n >= 0, NULL); + if (!convention) { return NULL; } + const char *query = sdb_fmt ("cc.%s.arg%d", convention, n); const char *ret = sdb_const_get (DB, query, 0); if (!ret) { diff --git a/libr/anal/meson.build b/libr/anal/meson.build index 1bb51501f6..cb28914c64 100644 --- a/libr/anal/meson.build +++ b/libr/anal/meson.build @@ -195,6 +195,7 @@ pkgconfig_mod.generate(r_anal, version: r2_version, name: 'r_anal', filebase: 'r_anal', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_reg', diff --git a/libr/asm/meson.build b/libr/asm/meson.build index 3579dc51ee..f217db722d 100644 --- a/libr/asm/meson.build +++ b/libr/asm/meson.build @@ -240,6 +240,7 @@ pkgconfig_mod.generate(r_asm, version: r2_version, name: 'r_asm', filebase: 'r_asm', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_syscall', diff --git a/libr/bin/meson.build b/libr/bin/meson.build index c0dadab4e3..5a1c6f00be 100644 --- a/libr/bin/meson.build +++ b/libr/bin/meson.build @@ -165,6 +165,7 @@ pkgconfig_mod.generate(r_bin, version: r2_version, name: 'r_bin', filebase: 'r_bin', + libraries: pkgcfg_sanitize_libs, requires: pkgconfig_magic_requires + [ 'r_util', 'r_io', diff --git a/libr/bp/meson.build b/libr/bp/meson.build index 11db104b2f..c8089d74f2 100644 --- a/libr/bp/meson.build +++ b/libr/bp/meson.build @@ -29,6 +29,7 @@ pkgconfig_mod.generate(r_bp, version: r2_version, name: 'r_bp', filebase: 'r_bp', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/config/meson.build b/libr/config/meson.build index 56aff8edca..430589c0aa 100644 --- a/libr/config/meson.build +++ b/libr/config/meson.build @@ -22,6 +22,7 @@ pkgconfig_mod.generate(r_config, version: r2_version, name: 'r_config', filebase: 'r_config', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/cons/meson.build b/libr/cons/meson.build index 36b3538eed..48922f07df 100644 --- a/libr/cons/meson.build +++ b/libr/cons/meson.build @@ -38,6 +38,7 @@ pkgconfig_mod.generate(r_cons, version: r2_version, name: 'r_cons', filebase: 'r_cons', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/core/canal.c b/libr/core/canal.c index 14df292f62..405e84406b 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -770,6 +770,7 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep return false; } fcn->cc = r_str_constpool_get (&core->anal->constpool, r_anal_cc_default (core->anal)); + r_warn_if_fail (!core->anal->sdb_cc->path || fcn->cc); hint = r_anal_hint_get (core->anal, at); if (hint && hint->bits == 16) { // expand 16bit for function diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 0201f93a70..6f95fe57da 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -1155,11 +1155,10 @@ static bool cb_dirhome(void *user, void *data) { return true; } -static bool cb_dirtmp (void *user, void *data) { - RConfigNode *node = (RConfigNode*) data; - if (node->value) { - r_sys_setenv (R_SYS_TMP, node->value); - } +static bool cb_dirtmp(void *user, void *data) { + RConfigNode *node = (RConfigNode *)data; + char *value = R_STR_ISNOTEMPTY (node->value)? node->value: NULL; + r_sys_setenv (R_SYS_TMP, value); return true; } diff --git a/libr/core/cfile.c b/libr/core/cfile.c index 0c64f566ff..7be910c8a0 100644 --- a/libr/core/cfile.c +++ b/libr/core/cfile.c @@ -438,7 +438,11 @@ static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loada return false; } binfile = r_bin_cur (r->bin); - r_core_bin_set_env (r, binfile); + if (r_core_bin_set_env (r, binfile)) { + if (!r->anal->sdb_cc->path) { + R_LOG_WARN ("No calling convention defined for this file, analysis may be inaccurate.\n"); + } + } plugin = r_bin_file_cur_plugin (binfile); if (plugin && !strcmp (plugin->name, "any")) { RBinObject *obj = r_bin_cur_object (r->bin); diff --git a/libr/core/cmd.c b/libr/core/cmd.c index ca11339a1c..43e5d3597d 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -1740,6 +1740,7 @@ static bool cmd_r2cmd(RCore *core, const char *_input) { return true; } } + free (input); return false; } free (input); @@ -2630,7 +2631,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { if (*hash == '\\') { hash++; if (*hash == '#') { - hash++; + continue; } } if (*hash == '#') { diff --git a/libr/core/meson.build b/libr/core/meson.build index 574596a75d..0299bd4b3b 100644 --- a/libr/core/meson.build +++ b/libr/core/meson.build @@ -128,6 +128,7 @@ pkgconfig_mod.generate( version: r2_version, name: 'r_core', filebase: 'r_core', + libraries: pkgcfg_sanitize_libs, requires: pkgconfig_magic_requires + [ 'r_util', 'r_reg', diff --git a/libr/crypto/meson.build b/libr/crypto/meson.build index 673d987037..d58c1b43f6 100644 --- a/libr/crypto/meson.build +++ b/libr/crypto/meson.build @@ -38,6 +38,7 @@ pkgconfig_mod.generate(r_crypto, version: r2_version, name: 'r_crypto', filebase: 'r_crypto', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/debug/meson.build b/libr/debug/meson.build index cf0557ddd5..4d6bb92dcf 100644 --- a/libr/debug/meson.build +++ b/libr/debug/meson.build @@ -115,6 +115,7 @@ pkgconfig_mod.generate(r_debug, version: r2_version, name: 'r_debug', filebase: 'r_debug', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_hash', diff --git a/libr/egg/meson.build b/libr/egg/meson.build index 508bfbf128..ea6f0c8741 100644 --- a/libr/egg/meson.build +++ b/libr/egg/meson.build @@ -36,6 +36,7 @@ pkgconfig_mod.generate(r_egg, version: r2_version, name: 'r_egg', filebase: 'r_egg', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_asm', diff --git a/libr/flag/meson.build b/libr/flag/meson.build index 2826f38ec0..a69fd3ad5b 100644 --- a/libr/flag/meson.build +++ b/libr/flag/meson.build @@ -23,6 +23,7 @@ pkgconfig_mod.generate(r_flag, version: r2_version, name: 'r_flag', filebase: 'r_flag', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/fs/meson.build b/libr/fs/meson.build index e4514208a6..e6235b1030 100644 --- a/libr/fs/meson.build +++ b/libr/fs/meson.build @@ -46,6 +46,7 @@ pkgconfig_mod.generate(r_fs, version: r2_version, name: 'r_fs', filebase: 'r_fs', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/hash/meson.build b/libr/hash/meson.build index e8dd39cc61..693fc9b65f 100644 --- a/libr/hash/meson.build +++ b/libr/hash/meson.build @@ -41,6 +41,7 @@ pkgconfig_mod.generate(r_hash, version: r2_version, name: 'r_hash', filebase: 'r_hash', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/io/meson.build b/libr/io/meson.build index 996dabd63c..5ef137e543 100644 --- a/libr/io/meson.build +++ b/libr/io/meson.build @@ -94,6 +94,7 @@ pkgconfig_mod.generate(r_io, version: r2_version, name: 'r_io', filebase: 'r_io', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_socket' diff --git a/libr/lang/meson.build b/libr/lang/meson.build index 18fd86f24d..6cbf565a6b 100644 --- a/libr/lang/meson.build +++ b/libr/lang/meson.build @@ -30,6 +30,7 @@ pkgconfig_mod.generate(r_lang, version: r2_version, name: 'r_lang', filebase: 'r_lang', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_cons' diff --git a/libr/magic/meson.build b/libr/magic/meson.build index ee992e8a9e..101ea8b61d 100644 --- a/libr/magic/meson.build +++ b/libr/magic/meson.build @@ -36,6 +36,7 @@ pkgconfig_mod.generate(r_magic, version: r2_version, name: 'r_magic', filebase: 'r_magic', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/main/meson.build b/libr/main/meson.build index c3f0c9aec8..8e6e7ad8b5 100644 --- a/libr/main/meson.build +++ b/libr/main/meson.build @@ -56,6 +56,7 @@ pkgconfig_mod.generate(r_main, subdirs: 'libr', version: r2_version, name: 'r_main', + libraries: pkgcfg_sanitize_libs, filebase: 'r_main', requires: [ 'r_core', diff --git a/libr/parse/meson.build b/libr/parse/meson.build index 599ea43e40..149fa081be 100644 --- a/libr/parse/meson.build +++ b/libr/parse/meson.build @@ -43,6 +43,7 @@ pkgconfig_mod.generate(r_parse, version: r2_version, name: 'r_parse', filebase: 'r_parse', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util', 'r_flag', diff --git a/libr/reg/meson.build b/libr/reg/meson.build index 726c166d0a..e63d83aabd 100644 --- a/libr/reg/meson.build +++ b/libr/reg/meson.build @@ -24,6 +24,7 @@ pkgconfig_mod.generate(r_reg, version: r2_version, name: 'r_reg', filebase: 'r_reg', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/search/meson.build b/libr/search/meson.build index 88a9007ef1..b0afd1ce5c 100644 --- a/libr/search/meson.build +++ b/libr/search/meson.build @@ -25,6 +25,7 @@ pkgconfig_mod.generate(r_search, version: r2_version, name: 'r_search', filebase: 'r_search', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/socket/meson.build b/libr/socket/meson.build index d518cbf42d..2e0f886343 100644 --- a/libr/socket/meson.build +++ b/libr/socket/meson.build @@ -33,6 +33,7 @@ pkgconfig_mod.generate(r_socket, version: r2_version, name: 'r_socket', filebase: 'r_socket', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/syscall/meson.build b/libr/syscall/meson.build index b770076240..813212e956 100644 --- a/libr/syscall/meson.build +++ b/libr/syscall/meson.build @@ -22,6 +22,7 @@ pkgconfig_mod.generate(r_syscall, version: r2_version, name: 'r_syscall', filebase: 'r_syscall', + libraries: pkgcfg_sanitize_libs, requires: [ 'r_util' ], diff --git a/libr/util/meson.build b/libr/util/meson.build index 5e71e7fda1..8362080088 100644 --- a/libr/util/meson.build +++ b/libr/util/meson.build @@ -112,6 +112,7 @@ r_util_dep = declare_dependency(link_with: r_util, pkgconfig_mod.generate(r_util, subdirs: 'libr', version: r2_version, + libraries: pkgcfg_sanitize_libs, name: 'r_util', filebase: 'r_util', description: 'radare foundation libraries' diff --git a/meson.build b/meson.build index 0eb2ee31bd..3508a9703d 100644 --- a/meson.build +++ b/meson.build @@ -398,6 +398,14 @@ libr_pc = configure_file( install_dir: join_paths(get_option('libdir'), 'pkgconfig') ) +pkgcfg_sanitize_libs = '' +if get_option('b_sanitize').contains('address') + pkgcfg_sanitize_libs += ' -lasan' +endif +if get_option('b_sanitize').contains('undefined') + pkgcfg_sanitize_libs += ' -lubsan' +endif + subdir('shlr') subdir('libr/util') diff --git a/test/db/archos/darwin-x64/cmd_interpreter b/test/db/archos/darwin-x64/cmd_interpreter index 8a20278f35..32164396b6 100644 --- a/test/db/archos/darwin-x64/cmd_interpreter +++ b/test/db/archos/darwin-x64/cmd_interpreter @@ -1,7 +1,7 @@ NAME=#!c FILE=- CMDS=<\nint entry(){printf(\"Hello\\n\");}" > .tmp-hashc.c +"?e #include \nint entry(){printf(\"Hello\\n\");return 0;}" > .tmp-hashc.c #!c .tmp-hashc.c rm .tmp-hashc.c EOF @@ -13,7 +13,7 @@ RUN NAME=#! with ext != name FILE=- CMDS=<\nint main(){printf(\"Hello\\n\");}" > .tmp-hashextname.c +"?e #include \nint main(){printf(\"Hello\\n\");return 0;}" > .tmp-hashextname.c #!cpipe .tmp-hashextname.c rm .tmp-hashextname.c EOF diff --git a/test/db/archos/linux-x64/cmd_interpreter b/test/db/archos/linux-x64/cmd_interpreter index 8a20278f35..32164396b6 100644 --- a/test/db/archos/linux-x64/cmd_interpreter +++ b/test/db/archos/linux-x64/cmd_interpreter @@ -1,7 +1,7 @@ NAME=#!c FILE=- CMDS=<\nint entry(){printf(\"Hello\\n\");}" > .tmp-hashc.c +"?e #include \nint entry(){printf(\"Hello\\n\");return 0;}" > .tmp-hashc.c #!c .tmp-hashc.c rm .tmp-hashc.c EOF @@ -13,7 +13,7 @@ RUN NAME=#! with ext != name FILE=- CMDS=<\nint main(){printf(\"Hello\\n\");}" > .tmp-hashextname.c +"?e #include \nint main(){printf(\"Hello\\n\");return 0;}" > .tmp-hashextname.c #!cpipe .tmp-hashextname.c rm .tmp-hashextname.c EOF