mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-22 22:06:50 +00:00
Fix #3901 - Cannot debug directories and follow symlinks
This commit is contained in:
parent
8ff4b566b3
commit
6f346b6d6d
@ -463,6 +463,10 @@ int main(int argc, char **argv, char **envp) {
|
||||
}
|
||||
}
|
||||
if (argv[optind] && r_file_is_directory (argv[optind])) {
|
||||
if (debug) {
|
||||
eprintf ("Error: Cannot debug directories, yet.\n");
|
||||
return 1;
|
||||
}
|
||||
if (chdir (argv[optind])) {
|
||||
eprintf ("Cannot open directory\n");
|
||||
return 1;
|
||||
|
@ -39,13 +39,13 @@ typedef struct r_hashtable64_t {
|
||||
R_API RHashTable* r_hashtable_new(void);
|
||||
R_API void r_hashtable_free(RHashTable *ht);
|
||||
R_API void *r_hashtable_lookup(RHashTable *ht, ut32 hash);
|
||||
R_API boolt r_hashtable_insert(RHashTable *ht, ut32 hash, void *data);
|
||||
R_API bool r_hashtable_insert(RHashTable *ht, ut32 hash, void *data);
|
||||
R_API void r_hashtable_remove(RHashTable *ht, ut32 hash);
|
||||
|
||||
R_API RHashTable64* r_hashtable64_new(void);
|
||||
R_API void r_hashtable64_free(RHashTable64 *ht);
|
||||
R_API void *r_hashtable64_lookup(RHashTable64 *ht, ut64 hash);
|
||||
R_API boolt r_hashtable64_insert(RHashTable64 *ht, ut64 hash, void *data);
|
||||
R_API bool r_hashtable64_insert(RHashTable64 *ht, ut64 hash, void *data);
|
||||
R_API void r_hashtable64_remove(RHashTable64 *ht, ut64 hash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -77,7 +77,7 @@ R_API void r_list_sort(RList *list, RListComparator cmp);
|
||||
|
||||
R_API void r_list_init(RList *list);
|
||||
R_API void r_list_delete(RList *list, RListIter *iter);
|
||||
R_API boolt r_list_delete_data(RList *list, void *ptr);
|
||||
R_API bool r_list_delete_data(RList *list, void *ptr);
|
||||
R_API void r_list_iter_init(RListIter *iter, RList *list);
|
||||
R_API void r_list_purge(RList *list);
|
||||
R_API void r_list_free(RList *list);
|
||||
|
@ -340,12 +340,12 @@ R_API void r_graph_dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis);
|
||||
R_API void r_graph_dfs (RGraph *g, RGraphVisitor *vis);
|
||||
|
||||
R_API int r_file_is_abspath(const char *file);
|
||||
R_API boolt r_file_truncate (const char *filename, ut64 newsize);
|
||||
R_API bool r_file_truncate (const char *filename, ut64 newsize);
|
||||
R_API ut64 r_file_size(const char *str);
|
||||
R_API char *r_file_root(const char *root, const char *path);
|
||||
R_API boolt r_file_is_directory(const char *str);
|
||||
R_API boolt r_file_is_regular(const char *str);
|
||||
R_API RMmap *r_file_mmap (const char *file, boolt rw, ut64 base);
|
||||
R_API bool r_file_is_directory(const char *str);
|
||||
R_API bool r_file_is_regular(const char *str);
|
||||
R_API RMmap *r_file_mmap (const char *file, bool rw, ut64 base);
|
||||
R_API int r_file_mmap_read (const char *file, ut64 addr, ut8 *buf, int len);
|
||||
R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len);
|
||||
R_API void r_file_mmap_free (RMmap *m);
|
||||
@ -611,13 +611,14 @@ R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz);
|
||||
R_API char *r_file_slurp_random_line(const char *file);
|
||||
R_API char *r_file_slurp_random_line_count(const char *file, int *linecount);
|
||||
R_API ut8 *r_file_slurp_hexpairs(const char *str, int *usz);
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append);
|
||||
R_API boolt r_file_rm(const char *file);
|
||||
R_API boolt r_file_exists(const char *str);
|
||||
R_API boolt r_file_fexists(const char *fmt, ...);
|
||||
R_API bool r_file_dump(const char *file, const ut8 *buf, int len, int append);
|
||||
R_API bool r_file_rm(const char *file);
|
||||
R_API bool r_file_exists(const char *str);
|
||||
R_API bool r_file_fexists(const char *fmt, ...);
|
||||
R_API char *r_file_slurp_line(const char *file, int line, int context);
|
||||
R_API int r_file_mkstemp(const char *prefix, char **oname);
|
||||
R_API char *r_file_tmpdir(void);
|
||||
R_API char *r_file_readlink (const char *path);
|
||||
|
||||
R_API ut64 r_sys_now(void);
|
||||
R_API int r_sys_fork(void);
|
||||
|
@ -273,6 +273,12 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
|
||||
cpu = CPU_TYPE_ANY;
|
||||
#endif
|
||||
posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &copied);
|
||||
{
|
||||
char *dst = r_file_readlink (argv[0]);
|
||||
if (dst) {
|
||||
argv[0] = dst;
|
||||
}
|
||||
}
|
||||
ret = posix_spawnp (&p, argv[0], &fileActions, &attr, argv, NULL);
|
||||
switch (ret) {
|
||||
case 0:
|
||||
@ -295,7 +301,6 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) {
|
||||
return p;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ret, status, child_pid;
|
||||
|
||||
child_pid = r_sys_fork ();
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
R_API boolt r_file_truncate (const char *filename, ut64 newsize) {
|
||||
R_API bool r_file_truncate (const char *filename, ut64 newsize) {
|
||||
int fd;
|
||||
if (r_file_is_directory (filename))
|
||||
return R_FALSE;
|
||||
@ -65,7 +65,7 @@ R_API char *r_file_dirname (const char *path) {
|
||||
return newpath;
|
||||
}
|
||||
|
||||
R_API boolt r_file_is_regular(const char *str) {
|
||||
R_API bool r_file_is_regular(const char *str) {
|
||||
struct stat buf = {0};
|
||||
if (!str||!*str)
|
||||
return R_FALSE;
|
||||
@ -74,7 +74,7 @@ R_API boolt r_file_is_regular(const char *str) {
|
||||
return ((S_IFREG & buf.st_mode)==S_IFREG)? R_TRUE: R_FALSE;
|
||||
}
|
||||
|
||||
R_API boolt r_file_is_directory(const char *str) {
|
||||
R_API bool r_file_is_directory(const char *str) {
|
||||
struct stat buf = {0};
|
||||
if (!str||!*str)
|
||||
return R_FALSE;
|
||||
@ -85,7 +85,7 @@ R_API boolt r_file_is_directory(const char *str) {
|
||||
return (S_IFDIR==(S_IFDIR & buf.st_mode))? R_TRUE: R_FALSE;
|
||||
}
|
||||
|
||||
R_API boolt r_file_fexists(const char *fmt, ...) {
|
||||
R_API bool r_file_fexists(const char *fmt, ...) {
|
||||
int ret;
|
||||
char string[1024];
|
||||
va_list ap;
|
||||
@ -96,7 +96,7 @@ R_API boolt r_file_fexists(const char *fmt, ...) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API boolt r_file_exists(const char *str) {
|
||||
R_API bool r_file_exists(const char *str) {
|
||||
struct stat buf = {0};
|
||||
if (str && *str && stat (str, &buf)==-1)
|
||||
return R_FALSE;
|
||||
@ -416,7 +416,7 @@ R_API char *r_file_root(const char *root, const char *path) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append) {
|
||||
R_API bool r_file_dump(const char *file, const ut8 *buf, int len, int append) {
|
||||
int ret;
|
||||
FILE *fd;
|
||||
if (!file || !*file || !buf) {
|
||||
@ -440,7 +440,7 @@ R_API boolt r_file_dump(const char *file, const ut8 *buf, int len, int append) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API boolt r_file_rm(const char *file) {
|
||||
R_API bool r_file_rm(const char *file) {
|
||||
if (r_sandbox_enable (0)) return R_FALSE;
|
||||
if (r_file_is_directory (file)) {
|
||||
#if __WINDOWS__
|
||||
@ -457,6 +457,25 @@ R_API boolt r_file_rm(const char *file) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API char *r_file_readlink(const char *path) {
|
||||
if (!r_sandbox_enable (0)) {
|
||||
#if __UNIX__
|
||||
int ret;
|
||||
char pathbuf[4096];
|
||||
strcpy (pathbuf, path);
|
||||
repeat:
|
||||
ret = readlink (path, pathbuf, sizeof (pathbuf)-1);
|
||||
if (ret != -1) {
|
||||
pathbuf[ret] = 0;
|
||||
path = pathbuf;
|
||||
goto repeat;
|
||||
}
|
||||
return strdup (pathbuf);
|
||||
#endif
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len) {
|
||||
#if __WINDOWS__
|
||||
HANDLE fh;
|
||||
@ -621,9 +640,8 @@ static RMmap *r_file_mmap_other (RMmap *m) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: add rwx support?
|
||||
R_API RMmap *r_file_mmap (const char *file, boolt rw, ut64 base) {
|
||||
R_API RMmap *r_file_mmap (const char *file, bool rw, ut64 base) {
|
||||
RMmap *m = NULL;
|
||||
int fd = -1;
|
||||
if (!rw && !r_file_exists (file)) return m;
|
||||
|
@ -192,7 +192,7 @@ R_API void *ht_(lookup)(RHT *ht, utH hash) {
|
||||
* Note that insertion may rearrange the table on a resize or rehash,
|
||||
* so previously found hash_entries are no longer valid after this function.
|
||||
*/
|
||||
R_API boolt ht_(insert) (RHT *ht, utH hash, void *data) {
|
||||
R_API bool ht_(insert) (RHT *ht, utH hash, void *data) {
|
||||
utH hash_address;
|
||||
|
||||
if (ht->entries >= ht->max_entries)
|
||||
|
@ -80,7 +80,7 @@ R_API void r_list_free (RList *list) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API boolt r_list_delete_data (RList *list, void *ptr) {
|
||||
R_API bool r_list_delete_data (RList *list, void *ptr) {
|
||||
void *p;
|
||||
RListIter *iter;
|
||||
r_list_foreach (list, iter, p) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user