Dont use large stack buffers and fix overflow in r2r (#18433)

This commit is contained in:
pancake 2021-03-10 18:01:07 +01:00 committed by GitHub
parent 5856257011
commit 4a3479ede3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,15 +77,15 @@ static bool r2r_chdir(const char *argv0) {
if (r_file_is_directory ("db")) { if (r_file_is_directory ("db")) {
return true; return true;
} }
char src_path[PATH_MAX]; char *src_path = malloc (PATH_MAX);
char *r2r_path = r_file_path (argv0); char *r2r_path = r_file_path (argv0);
bool found = false; bool found = false;
if (readlink (r2r_path, src_path, sizeof (src_path)) != -1) { if (readlink (r2r_path, src_path, PATH_MAX) != -1) {
src_path[sizeof (src_path) - 1] = 0; src_path[PATH_MAX - 1] = 0;
char *p = strstr (src_path, R_SYS_DIR "binr"R_SYS_DIR"r2r"R_SYS_DIR"r2r"); char *p = strstr (src_path, "/binr/r2r/r2r");
if (p) { if (p) {
*p = 0; *p = 0;
strcat (src_path, R_SYS_DIR"test"R_SYS_DIR); src_path = r_str_append (src_path, "/test/");
if (r_file_is_directory (src_path)) { if (r_file_is_directory (src_path)) {
if (chdir (src_path) != -1) { if (chdir (src_path) != -1) {
eprintf ("Running from %s\n", src_path); eprintf ("Running from %s\n", src_path);
@ -96,6 +96,7 @@ static bool r2r_chdir(const char *argv0) {
} }
} }
} }
free (src_path);
free (r2r_path); free (r2r_path);
return found; return found;
#else #else