qfile-agent: Handle filenames with trailing slash properly.

This commit is contained in:
Rafal Wojtczuk 2011-03-16 10:48:27 +01:00
parent e6da61cb5e
commit 5230c12934

View File

@ -57,15 +57,15 @@ int single_file_processor(char *filename, struct stat *st)
hdr.mtime_nsec = st->st_mtim.tv_nsec; hdr.mtime_nsec = st->st_mtim.tv_nsec;
if (S_ISREG(mode)) { if (S_ISREG(mode)) {
char * ret; char *ret;
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (!fd) if (!fd)
gui_fatal("open %s", filename); gui_fatal("open %s", filename);
hdr.filelen = st->st_size; hdr.filelen = st->st_size;
write_headers(&hdr, filename); write_headers(&hdr, filename);
ret=copy_file(1, fd, hdr.filelen); ret = copy_file(1, fd, hdr.filelen);
if (ret) if (ret)
gui_fatal("Copying file %s: %s", filename, ret); gui_fatal("Copying file %s: %s", filename, ret);
close(fd); close(fd);
} }
if (S_ISDIR(mode)) { if (S_ISDIR(mode)) {
@ -142,10 +142,13 @@ void parse_entry(char *data, int datasize)
notify_progress(0, 1); notify_progress(0, 1);
send_vmname(vmname); send_vmname(vmname);
while ((entry = get_item(data, &current, datasize))) { while ((entry = get_item(data, &current, datasize))) {
sep = rindex(entry, '/'); do {
if (!sep) sep = rindex(entry, '/');
gui_fatal("Internal error: nonabsolute filenames not allowed"); if (!sep)
*sep = 0; gui_fatal
("Internal error: nonabsolute filenames not allowed");
*sep = 0;
} while (sep[1] == 0);
if (entry[0] == 0) if (entry[0] == 0)
chdir("/"); chdir("/");
else if (chdir(entry)) else if (chdir(entry))
@ -188,8 +191,8 @@ void scan_spool(char *name)
char *fname = ent->d_name; char *fname = ent->d_name;
if (fname[0] != '.') { if (fname[0] != '.') {
process_spoolentry(fname); process_spoolentry(fname);
break; break;
} }
} }
closedir(dir); closedir(dir);
} }