Commit b6c91951 authored by Thomas Schmitt's avatar Thomas Schmitt

Bug fix: Paths with symbolic links preceding ".." were not interpreted properly

parent edaaf87e
......@@ -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;
......
......@@ -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<filec; i++) {
ret= Xorriso_make_abs_adr(xorriso, wd, filev[i], path, 1|2|4);
ret= Xorriso_make_abs_adr(xorriso, wd, filev[i], path, 1|2|4|8);
if(ret<=0) {
was_error++;
continue;
......
......@@ -42,8 +42,8 @@
/* @param eff_path returns resulting effective path.
Must provide at least SfileadrL bytes of storage.
@param flag bit0= do not produce problem events (unless faulty path format)
bit1= work purely literally, do not use libisofs
bit2= (with bit1) this is an address in the disk world
bit1= do not use libisofs (work literally or in disk world)
bit2= (implies bit1) this is an address in the disk world
bit3= return root directory as "/" and not as ""
bit4= (with bit2) determine type of disk file eff_path
and return 0 if not existing
......@@ -59,10 +59,13 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
IsoImage *volume;
IsoDir *dir= NULL;
IsoNode *node= NULL;
char *path= NULL, *apt, *npt, *cpt;
char *path= NULL, *apt, *npt, *cpt, *link_target= NULL;
Xorriso_alloc_meM(path, char, SfileadrL);
Xorriso_alloc_meM(link_target, char, SfileadrL);
if(flag & 4)
flag|= 2;
if((flag&64) || !(flag&2)) {
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
......@@ -129,13 +132,31 @@ bonked_root:;
{ret= -1; goto ex;}
}
dir= iso_node_get_parent(node);
/* >>> 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);
}
......
......@@ -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;
......
#define Xorriso_timestamP "2014.02.09.141412"
#define Xorriso_timestamP "2014.02.10.104827"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment