diff --git a/xorriso/base_obj.c b/xorriso/base_obj.c index 07451919..81f9a9fc 100644 --- a/xorriso/base_obj.c +++ b/xorriso/base_obj.c @@ -157,6 +157,8 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag) m->do_follow_param= 0; m->do_follow_links= 0; m->follow_link_limit= 100; + m->resolve_link_rec_count= 0; + m->resolve_link_rec_limit= 100; m->do_follow_mount= 1; m->do_global_uid= 0; m->global_uid= 0; diff --git a/xorriso/disk_ops.c b/xorriso/disk_ops.c index 3d0c129d..36d9c4f7 100644 --- a/xorriso/disk_ops.c +++ b/xorriso/disk_ops.c @@ -35,9 +35,10 @@ /* @param flag bit0= simple readlink(): no normalization, no multi-hop + bit1= this is potentially a recursion */ -int Xorriso_resolve_link(struct XorrisO *xorriso, - char *link_path, char result_path[SfileadrL], int flag) +int Xorriso_resolve_link(struct XorrisO *xorriso, char *link_path, + char result_path[SfileadrL], int flag) { ssize_t l; struct stat stbuf; @@ -45,6 +46,19 @@ int Xorriso_resolve_link(struct XorrisO *xorriso, char *buf= NULL, *dirbuf= NULL, *lpt, *spt; static int link_limit= 100; + if(flag & 1) { + xorriso->resolve_link_rec_count++; + if(xorriso->resolve_link_rec_count > xorriso->resolve_link_rec_limit) { + Xorriso_msgs_submit(xorriso, 0, link_path, 0, "ERRFILE", 0); + sprintf(xorriso->info_text, "Too many link recursions before : "); + Text_shellsafe(link_path, xorriso->info_text, 1); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, show_errno, + "FAILURE", 0); + {ret= 0; goto ex;} + } + } else + xorriso->resolve_link_rec_count= 0; + Xorriso_alloc_meM(buf, char, SfileadrL); Xorriso_alloc_meM(dirbuf, char, SfileadrL); @@ -99,8 +113,9 @@ handle_abort:; break; } ret= Xorriso_normalize_img_path(xorriso, dirbuf, buf, result_path, 2|4); - if(ret<=0) + if(ret<=0) { goto ex; + } if(lstat(result_path, &stbuf)==-1) { lpt= result_path; @@ -125,6 +140,8 @@ too_many_hops:; ex:; Xorriso_free_meM(buf); Xorriso_free_meM(dirbuf); + if(xorriso->resolve_link_rec_count > 0) + xorriso->resolve_link_rec_count--; return(ret); } @@ -806,7 +823,7 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd, /* Count valid nodes, warn of invalid ones */ for(i= 0; i>> Get absolute path of dir as eff_path, to avoid link problems */; + } + if(flag & 4) { + /* Linux-ish local filesystem semantics: + If the parent is a symbolic link, do not ascend to its parent, + but to the parent of the link target. + >>> ??? Are there systems which do it differently ? + */ + if(Sfile_type(eff_path, 0) == 3) { + ret= Xorriso_resolve_link(xorriso, eff_path, link_target, 2); + if(ret <= 0) + {ret= -1; goto ex;} + strcpy(eff_path, link_target); + } + } + /* truncate eff_path */; cpt= strrchr(eff_path, '/'); if(cpt==NULL) /* ??? if not flag&2 then this is a bug */ goto bonked_root; *cpt= 0; is_dir= 1; + continue; } is_dir= 0; @@ -171,6 +192,7 @@ much_too_long:; ret= 1+!!is_dir; ex:; Xorriso_free_meM(path); + Xorriso_free_meM(link_target); return(ret); } diff --git a/xorriso/xorriso_private.h b/xorriso/xorriso_private.h index f4c79654..b4ec5cf1 100644 --- a/xorriso/xorriso_private.h +++ b/xorriso/xorriso_private.h @@ -190,6 +190,8 @@ struct XorrisO { /* the global context of xorriso */ int do_follow_param; int do_follow_links; int follow_link_limit; + int resolve_link_rec_count; + int resolve_link_rec_limit; int do_follow_mount; int do_global_uid; uid_t global_uid; diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index 2ed6875c..93672903 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2014.02.09.141412" +#define Xorriso_timestamP "2014.02.10.104827"