Hello,

I have recently been researching the possibility of using libtcc to make C a highly efficient scripting language for my codebase. The idea is certainly very promising - at a similar level of visible abstraction, TCC takes two seconds to allocate a single-gigabyte array on my setup, Lua takes about five... to trigger OOM :-)

However, it appears that if if I use the -rdynamic flag while compiling the codebase, the TCC state is being given access to symbols that have not been explicitly added to it - I've attached the code of a simple program showcasing the issue. Because CMake exposes this flag by default to the *nix compiler toolchains (spent quite a while scratching my head...), this may be a fairly serious vulnerability if unnoticed.

I would therefore love to get an answer on whether the described behavior is intentional. If it indeed is - TCC should probably get it visibly documented for the benefit of security and easier adoption of the library. If not - well, I've tried to fix it and failed (or rather, succeeded while making a thousand other things break, by changing RTLD_DEFAULT to RTLD_NEXT in tccelf.c:823), so if anybody here happened to be blessed with actual know-how... :-)

Thank You a thousand times to all the great contributors to this outstanding project!

- Czcibor

#include <libtcc.h>

const char* code = "#include <stdio.h> \n\
extern float add(float a, float b); \n\
int main() { \n\
	printf(\"%f\\n\", add(1, 2)); \n\
	return 0; \n\
}";

float add(float a, float b) {
	return a + b;
}
int main() {
	void* func;
	TCCState *s = tcc_new();
	tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
	//tcc_add_symbol(s, "add", (void*) add);
	if(tcc_compile_string(s, code) == -1 || tcc_relocate(s, TCC_RELOCATE_AUTO) < 0 || !(func = tcc_get_symbol(s, "main"))) {
		tcc_delete(s);
		return 1;
	}
	((int (*)()) func)();
	
	//build with tcc seetcc.c -rdynamic -Wall -ldl -ltcc
	//expected output: tcc: error: undefined symbol 'add'
	//actual output: 3.000000
	
	tcc_delete(s);
	return 0;
}
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to