2000-05-15 Andrew V. Samoilov <sav@bcs.zp.ua>

* tar.c (read_header): memory leaking for empty symlink's names fixed

	* utilvfs.c (vfs_split_url): *host is not assigned if host is null

	* ftpfs.c (login_server): new features of vfs_split_url () used,
	  my_get_host_and_username became macro

	* vfs.c (mc_opendir, mc_chdir): unneeded calls to concat_dir_and_file
	  removed (vfs_canon removes trailing '/')

	* sfs.c (vfmake, redirect): allocated memory realeased on errors
This commit is contained in:
Pavel Machek 2000-05-16 14:59:33 +00:00
parent ff8060efbc
commit c319041ba8
6 changed files with 76 additions and 75 deletions

View File

@ -1,3 +1,17 @@
2000-05-15 Andrew V. Samoilov <sav@bcs.zp.ua>
* tar.c (read_header): memory leaking for empty symlink's names fixed
* utilvfs.c (vfs_split_url): *host is not assigned if host is null
* ftpfs.c (login_server): new features of vfs_split_url () used,
my_get_host_and_username became macro
* vfs.c (mc_opendir, mc_chdir): unneeded calls to concat_dir_and_file
removed (vfs_canon removes trailing '/')
* sfs.c (vfmake, redirect): allocated memory realeased on errors
2000-05-10 Pavel Machek <pavel@artax.karlin.mff.cuni.cz> 2000-05-10 Pavel Machek <pavel@artax.karlin.mff.cuni.cz>
* direntry.c (vfs_s_new_inode): Do not leave st_nlink uninitialized. * direntry.c (vfs_s_new_inode): Do not leave st_nlink uninitialized.

View File

@ -212,11 +212,8 @@ translate_path (vfs *me, vfs_s_super *super, const char *remote_path)
#define FTP_COMMAND_PORT 21 #define FTP_COMMAND_PORT 21
#define HSC_PROXY_PORT 9875 #define HSC_PROXY_PORT 9875
static char * #define my_get_host_and_username (path, host, user, port, pass) \
my_get_host_and_username (char *path, char **host, char **user, int *port, char **pass) vfs_split_url (path, host, user, port, pass, FTP_COMMAND_PORT, URL_DEFAULTANON)
{
return vfs_split_url (path, host, user, port, pass, FTP_COMMAND_PORT, URL_DEFAULTANON);
}
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */ /* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
static int static int
@ -386,26 +383,22 @@ login_server (vfs *me, vfs_s_super *super, char *netrcpass)
} }
if (!anon || logfile) if (!anon || logfile)
pass = g_strdup (op); pass = op;
else else {
pass = g_strconcat ("-", op, NULL); pass = g_strconcat ("-", op, NULL);
if (op) wipe_password (op);
wipe_password (op); }
/* Proxy server accepts: username@host-we-want-to-connect*/ /* Proxy server accepts: username@host-we-want-to-connect*/
if (SUP.proxy){ if (SUP.proxy){
#if defined(HSC_PROXY) #if defined(HSC_PROXY)
char *p, *host; char *p;
int port; int port;
p = my_get_host_and_username (ftpfs_proxy_host, &host, &proxyname, p = my_get_host_and_username (ftpfs_proxy_host, 0, &proxyname,
&port, &proxypass); &port, 0);
if (p) if (p)
g_free (p); g_free (p);
g_free (host);
if (proxypass)
wipe_password (proxypass);
p = g_strconcat (_(" Proxy: Password required for "), proxyname, " ", p = g_strconcat (_(" Proxy: Password required for "), proxyname, " ",
NULL); NULL);
proxypass = vfs_get_password (p); proxypass = vfs_get_password (p);

View File

@ -73,25 +73,27 @@ static int vfmake (vfs *me, char *name, char *cache)
g_free (s); g_free (s);
} else } else
name = name_quote (name, 0); name = name_quote (name, 0);
s = sfs_command[w]; #define COPY_CHAR if (t-pad>sizeof(pad)) { g_free (name); return -1; } else *t++ = *s;
#define COPY_CHAR if (t-pad>10200) return -1; else *t++ = *s; #define COPY_STRING(a) if ((t-pad)+strlen(a)>sizeof(pad)) { g_free (name); return -1; } else { strcpy (t, a); t+= strlen(a); }
#define COPY_STRING(a) if ((t-pad)+strlen(a)>10200) return -1; else { strcpy (t, a); t+= strlen(a); } for (s = sfs_command[w]; *s; s++) {
while (*s) {
if (was_percent) { if (was_percent) {
switch (*s) {
case '1': COPY_STRING (name); break; char *ptr = NULL;
case '2': COPY_STRING (op + strlen (sfs_prefix[w])); break;
case '3': COPY_STRING (cache); break;
case '%': COPY_CHAR; break;
}
was_percent = 0; was_percent = 0;
switch (*s) {
case '1': ptr = name; break;
case '2': ptr = op + strlen (sfs_prefix[w]); break;
case '3': ptr = cache; break;
case '%': COPY_CHAR; continue;
}
COPY_STRING (ptr);
} else { } else {
if (*s == '%') if (*s == '%')
was_percent = 1; was_percent = 1;
else else
COPY_CHAR; COPY_CHAR;
} }
s++;
} }
g_free (name); g_free (name);
@ -107,7 +109,7 @@ redirect (vfs *me, char *name)
{ {
struct cachedfile *cur = head; struct cachedfile *cur = head;
uid_t uid = vfs_uid; uid_t uid = vfs_uid;
char *cache, *xname; char *cache;
int handle; int handle;
while (cur){ while (cur){
@ -124,15 +126,16 @@ redirect (vfs *me, char *name)
cache = tempnam (NULL, "sfs"); cache = tempnam (NULL, "sfs");
handle = open (cache, O_RDWR | O_CREAT | O_EXCL, 0600); handle = open (cache, O_RDWR | O_CREAT | O_EXCL, 0600);
if (handle == -1) if (handle == -1) {
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US"; g_free (cache);
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
}
close (handle); close (handle);
xname = g_strdup (name);
if (!vfmake (me, name, cache)){ if (!vfmake (me, name, cache)){
cur = g_new (struct cachedfile, 1); cur = g_new (struct cachedfile, 1);
cur->name = xname; cur->name = g_strdup (name);
cur->cache = cache; cur->cache = cache;
cur->uid = uid; cur->uid = uid;
cur->next = head; cur->next = head;
@ -142,9 +145,8 @@ redirect (vfs *me, char *name)
vfs_rm_parents (NULL); vfs_rm_parents (NULL);
return cache; return cache;
} else {
g_free(xname);
} }
g_free (cache);
return "/I_MUST_NOT_EXIST"; return "/I_MUST_NOT_EXIST";
} }

View File

@ -206,11 +206,7 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
register long sum, signed_sum, recsum; register long sum, signed_sum, recsum;
register char *p; register char *p;
register union record *header; register union record *header;
char **longp;
char *bp, *data;
int size, written;
static char *next_long_name = NULL, *next_long_link = NULL; static char *next_long_name = NULL, *next_long_link = NULL;
char *current_file_name, *current_link_name;
recurse: recurse:
@ -253,8 +249,8 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
* linkflag on BSDI tar (pax) always '\000' * linkflag on BSDI tar (pax) always '\000'
*/ */
if (header->header.linkflag == '\000' && if (header->header.linkflag == '\000' &&
strlen(header->header.arch_name) && (i = strlen(header->header.arch_name)) &&
header->header.arch_name[strlen(header->header.arch_name) - 1] == '/') header->header.arch_name[i - 1] == '/')
header->header.linkflag = LF_DIR; header->header.linkflag = LF_DIR;
/* /*
@ -268,6 +264,10 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
header->header.arch_name[NAMSIZ - 1] = '\0'; header->header.arch_name[NAMSIZ - 1] = '\0';
if (header->header.linkflag == LF_LONGNAME if (header->header.linkflag == LF_LONGNAME
|| header->header.linkflag == LF_LONGLINK) { || header->header.linkflag == LF_LONGLINK) {
char **longp;
char *bp, *data;
int size, written;
longp = ((header->header.linkflag == LF_LONGNAME) longp = ((header->header.linkflag == LF_LONGNAME)
? &next_long_name ? &next_long_name
: &next_long_link); : &next_long_link);
@ -301,18 +301,9 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
struct vfs_s_entry *entry; struct vfs_s_entry *entry;
struct vfs_s_inode *inode, *parent; struct vfs_s_inode *inode, *parent;
long data_position; long data_position;
char *p, *q; char *q;
int len; int len;
int isdir = 0; char *current_file_name, *current_link_name;
current_file_name = (next_long_name
? next_long_name
: g_strdup (header->header.arch_name));
len = strlen (current_file_name);
if (current_file_name[len - 1] == '/') {
current_file_name[len - 1] = 0;
isdir = 1;
}
current_link_name = (next_long_link current_link_name = (next_long_link
? next_long_link ? next_long_link
@ -321,14 +312,20 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
if (len > 1 && current_link_name [len - 1] == '/') if (len > 1 && current_link_name [len - 1] == '/')
current_link_name[len - 1] = 0; current_link_name[len - 1] = 0;
next_long_link = next_long_name = NULL; current_file_name = (next_long_name
? next_long_name
: g_strdup (header->header.arch_name));
len = strlen (current_file_name);
if (current_file_name[len - 1] == '/') {
current_file_name[len - 1] = 0;
}
data_position = current_tar_position; data_position = current_tar_position;
p = strrchr (current_file_name, '/'); p = strrchr (current_file_name, '/');
if (p == NULL) { if (p == NULL) {
p = current_file_name; p = current_file_name;
q = current_file_name + strlen (current_file_name); /* "" */ q = current_file_name + len; /* "" */
} else { } else {
*(p++) = 0; *(p++) = 0;
q = current_file_name; q = current_file_name;
@ -356,14 +353,19 @@ read_header (vfs *me, vfs_s_super *archive, int tard)
inode = vfs_s_new_inode (me, archive, &st); inode = vfs_s_new_inode (me, archive, &st);
inode->u.tar.data_offset = data_position; inode->u.tar.data_offset = data_position;
if (*current_link_name) if (*current_link_name) {
inode->linkname = current_link_name; inode->linkname = current_link_name;
} else if (current_link_name != next_long_link) {
g_free (current_link_name);
}
entry = vfs_s_new_entry (me, p, inode); entry = vfs_s_new_entry (me, p, inode);
vfs_s_insert_entry (me, parent, entry); vfs_s_insert_entry (me, parent, entry);
g_free (current_file_name); g_free (current_file_name);
done: done:
next_long_link = next_long_name = NULL;
if (header->header.isextended) { if (header->header.isextended) {
while (get_next_record (archive, tard)->ext_hdr.isextended); while (get_next_record (archive, tard)->ext_hdr.isextended);
inode->u.tar.data_offset = current_tar_position; inode->u.tar.data_offset = current_tar_position;

View File

@ -18,7 +18,7 @@
License along with this program; if not, write to the Free Software License along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Namespace: exports vfs_get_host_and_username */ /* Namespace: exports vfs_split_url */
#ifndef test_get_host_and_username #ifndef test_get_host_and_username
#include <config.h> #include <config.h>
@ -56,7 +56,7 @@
* If the user is empty, e.g. ftp://@roxanne/private, then your login name * If the user is empty, e.g. ftp://@roxanne/private, then your login name
* is supplied. * is supplied.
* *
* returns malloced host, user and pass if pass is not null. * returns malloced host if host isn't null, user and pass if pass is not null.
* returns a malloced strings with the pathname relative to the host. * returns a malloced strings with the pathname relative to the host.
* */ * */
@ -67,7 +67,7 @@ char *vfs_split_url (char *path, char **host, char **user, int *port, char **pas
char *dir, *colon, *inner_colon, *at, *rest; char *dir, *colon, *inner_colon, *at, *rest;
char *retval; char *retval;
char *pcopy = g_strdup (path); char *pcopy = g_strdup (path);
char *pend = pcopy + strlen (pcopy); char *pend = pcopy + strlen (pcopy);
int default_is_anon = flags & URL_DEFAULTANON; int default_is_anon = flags & URL_DEFAULTANON;
if (pass) if (pass)
@ -79,8 +79,8 @@ char *vfs_split_url (char *path, char **host, char **user, int *port, char **pas
dir = pcopy; dir = pcopy;
if (!(flags & URL_NOSLASH)) { if (!(flags & URL_NOSLASH)) {
/* locate path component */ /* locate path component */
for (; *dir != PATH_SEP && *dir; dir++) while (*dir != PATH_SEP && *dir)
; dir++;
if (*dir){ if (*dir){
retval = g_strdup (dir); retval = g_strdup (dir);
*dir = 0; *dir = 0;
@ -98,7 +98,7 @@ char *vfs_split_url (char *path, char **host, char **user, int *port, char **pas
if (inner_colon){ if (inner_colon){
*inner_colon = 0; *inner_colon = 0;
inner_colon++; inner_colon++;
if (pass && (*inner_colon != '@')) if (pass)
*pass = g_strdup (inner_colon); *pass = g_strdup (inner_colon);
} }
if (*pcopy != 0) if (*pcopy != 0)
@ -143,8 +143,8 @@ char *vfs_split_url (char *path, char **host, char **user, int *port, char **pas
} }
} }
} }
if (host)
*host = g_strdup (rest); *host = g_strdup (rest);
g_free (pcopy); g_free (pcopy);
return retval; return retval;

View File

@ -506,18 +506,12 @@ mc_opendir (char *dirname)
int handle, *handlep; int handle, *handlep;
void *info; void *info;
vfs *vfs; vfs *vfs;
char *p = NULL;
/* We should make possible reading of the root directory in a tar file */
dirname = p = concat_dir_and_file (dirname, "");
dirname = vfs_canon (dirname); dirname = vfs_canon (dirname);
vfs = vfs_type (dirname); vfs = vfs_type (dirname);
info = vfs->opendir ? (*vfs->opendir)(vfs, dirname) : NULL; info = vfs->opendir ? (*vfs->opendir)(vfs, dirname) : NULL;
g_free (dirname); g_free (dirname);
if (p)
g_free (p);
if (!info){ if (!info){
errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP; errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP;
return NULL; return NULL;
@ -886,9 +880,6 @@ mc_chdir (char *path)
vfsid oldvfsid; vfsid oldvfsid;
struct vfs_stamping *parent; struct vfs_stamping *parent;
/* We should make possible reading of the root directory in a tar archive */
path = p = concat_dir_and_file (path, "");
a = current_dir; /* Save a copy for case of failure */ a = current_dir; /* Save a copy for case of failure */
current_dir = vfs_canon (path); current_dir = vfs_canon (path);
current_vfs = vfs_type (current_dir); current_vfs = vfs_type (current_dir);
@ -907,7 +898,6 @@ mc_chdir (char *path)
vfs_add_noncurrent_stamps (oldvfs, oldvfsid, parent); vfs_add_noncurrent_stamps (oldvfs, oldvfsid, parent);
vfs_rm_parents (parent); vfs_rm_parents (parent);
} }
g_free (p);
if (*current_dir){ if (*current_dir){
p = strchr (current_dir, 0) - 1; p = strchr (current_dir, 0) - 1;
@ -1792,7 +1782,7 @@ error:
if (++errorcount < 5) { if (++errorcount < 5) {
message_1s (1, _("Could not parse:"), p_copy); message_1s (1, _("Could not parse:"), p_copy);
} else if (errorcount >= 5) } else if (errorcount == 5)
message_1s (1, _("More parsing errors will be ignored."), _("(sorry)")); message_1s (1, _("More parsing errors will be ignored."), _("(sorry)"));
} }