introduced new type SHELL_ESCAPED_STR for more type safety
Этот коммит содержится в:
родитель
6674647676
Коммит
90763ba82f
@ -1,3 +1,8 @@
|
|||||||
|
2009-0-27 Enrico Weigelt, metux ITS <weigelt@metux.de>
|
||||||
|
|
||||||
|
* mhl/escape.h, src/complete.c, vfs/fish.c: introduced new type
|
||||||
|
SHELL_ESCAPED_STR for more type safety
|
||||||
|
|
||||||
2009-01-25 Ilia Maslakov <il.smind@gmail.com>
|
2009-01-25 Ilia Maslakov <il.smind@gmail.com>
|
||||||
|
|
||||||
* src/boxes.c, src/boxes.h, src/dir.c, src/dir.h:
|
* src/boxes.c, src/boxes.h, src/dir.c, src/dir.h:
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
#define mhl_shell_escape_nottoesc(x) \
|
#define mhl_shell_escape_nottoesc(x) \
|
||||||
(((x)!=0) && (!mhl_shell_escape_toesc((x))))
|
(((x)!=0) && (!mhl_shell_escape_toesc((x))))
|
||||||
|
|
||||||
|
/* type for escaped string - just for a bit more type safety ;-p */
|
||||||
|
typedef struct { char* s; } SHELL_ESCAPED_STR;
|
||||||
|
|
||||||
/** To be compatible with the general posix command lines we have to escape
|
/** To be compatible with the general posix command lines we have to escape
|
||||||
strings for the command line
|
strings for the command line
|
||||||
|
|
||||||
@ -26,10 +29,10 @@
|
|||||||
/returns
|
/returns
|
||||||
return escaped string (later need to free)
|
return escaped string (later need to free)
|
||||||
*/
|
*/
|
||||||
static inline char* mhl_shell_escape_dup(const char* src)
|
static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src)
|
||||||
{
|
{
|
||||||
if ((src==NULL)||(!(*src)))
|
if ((src==NULL)||(!(*src)))
|
||||||
return strdup("");
|
return (SHELL_ESCAPED_STR){ .s = strdup("") };
|
||||||
|
|
||||||
char* buffer = calloc(1, strlen(src)*2+2);
|
char* buffer = calloc(1, strlen(src)*2+2);
|
||||||
char* ptr = buffer;
|
char* ptr = buffer;
|
||||||
@ -48,7 +51,7 @@ static inline char* mhl_shell_escape_dup(const char* src)
|
|||||||
|
|
||||||
/* at this point we either have an \0 or an char to escape */
|
/* at this point we either have an \0 or an char to escape */
|
||||||
if (!c)
|
if (!c)
|
||||||
return buffer;
|
return (SHELL_ESCAPED_STR){ .s = buffer };
|
||||||
|
|
||||||
*ptr = '\\';
|
*ptr = '\\';
|
||||||
ptr++;
|
ptr++;
|
||||||
|
@ -954,17 +954,18 @@ complete_engine (WInput *in, int what_to_do)
|
|||||||
start++;
|
start++;
|
||||||
in->completions = try_complete (in->buffer, &start, &end, in->completion_flags);
|
in->completions = try_complete (in->buffer, &start, &end, in->completion_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in->completions){
|
if (in->completions){
|
||||||
if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) {
|
if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) {
|
||||||
complete = mhl_shell_escape_dup(in->completions [0]);
|
SHELL_ESCAPED_STR complete = mhl_shell_escape_dup(in->completions [0]);
|
||||||
if (insert_text (in, complete, strlen (complete))){
|
if (insert_text (in, complete.s, strlen (complete.s))){
|
||||||
if (in->completions [1])
|
if (in->completions [1])
|
||||||
beep ();
|
beep ();
|
||||||
else
|
else
|
||||||
free_completions (in);
|
free_completions (in);
|
||||||
} else
|
} else
|
||||||
beep ();
|
beep ();
|
||||||
mhl_mem_free(complete);
|
mhl_mem_free(complete.s);
|
||||||
}
|
}
|
||||||
if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) {
|
if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) {
|
||||||
int maxlen = 0, i, count = 0;
|
int maxlen = 0, i, count = 0;
|
||||||
@ -976,7 +977,8 @@ complete_engine (WInput *in, int what_to_do)
|
|||||||
|
|
||||||
for (p=in->completions + 1; *p; count++, p++) {
|
for (p=in->completions + 1; *p; count++, p++) {
|
||||||
q = *p;
|
q = *p;
|
||||||
*p = mhl_shell_escape_dup(*p);
|
SHELL_ESCAPED_STR esc = mhl_shell_escape_dup(*p);
|
||||||
|
*p = esc.s;
|
||||||
mhl_mem_free(q);
|
mhl_mem_free(q);
|
||||||
if ((i = strlen (*p)) > maxlen)
|
if ((i = strlen (*p)) > maxlen)
|
||||||
maxlen = i;
|
maxlen = i;
|
||||||
|
87
vfs/fish.c
87
vfs/fish.c
@ -144,7 +144,7 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
enable_interrupt_key ();
|
enable_interrupt_key ();
|
||||||
|
|
||||||
status = write (SUP.sockw, str, strlen (str));
|
status = write (SUP.sockw, str, strlen (str));
|
||||||
g_free (str);
|
mhl_mem_free (str);
|
||||||
|
|
||||||
disable_interrupt_key ();
|
disable_interrupt_key ();
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
@ -168,10 +168,10 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
close (SUP.sockr);
|
close (SUP.sockr);
|
||||||
SUP.sockw = SUP.sockr = -1;
|
SUP.sockw = SUP.sockr = -1;
|
||||||
}
|
}
|
||||||
g_free (SUP.host);
|
mhl_mem_free (SUP.host);
|
||||||
g_free (SUP.user);
|
mhl_mem_free (SUP.user);
|
||||||
g_free (SUP.cwdir);
|
mhl_mem_free (SUP.cwdir);
|
||||||
g_free (SUP.password);
|
mhl_mem_free (SUP.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -251,7 +251,7 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
p = g_strconcat (_(" fish: Password required for "),
|
p = g_strconcat (_(" fish: Password required for "),
|
||||||
SUP.user, " ", (char *) NULL);
|
SUP.user, " ", (char *) NULL);
|
||||||
op = vfs_get_password (p);
|
op = vfs_get_password (p);
|
||||||
g_free (p);
|
mhl_mem_free (p);
|
||||||
if (op == NULL)
|
if (op == NULL)
|
||||||
ERRNOR (EPERM, -1);
|
ERRNOR (EPERM, -1);
|
||||||
SUP.password = op;
|
SUP.password = op;
|
||||||
@ -314,7 +314,7 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
|
p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
|
||||||
&password, 0, URL_NOSLASH);
|
&password, 0, URL_NOSLASH);
|
||||||
|
|
||||||
g_free (p);
|
mhl_mem_free (p);
|
||||||
|
|
||||||
SUP.host = host;
|
SUP.host = host;
|
||||||
SUP.user = user;
|
SUP.user = user;
|
||||||
@ -341,12 +341,12 @@ fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
|
op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
|
||||||
URL_NOSLASH);
|
URL_NOSLASH);
|
||||||
|
|
||||||
g_free (op);
|
mhl_mem_free (op);
|
||||||
|
|
||||||
flags = ((strcmp (host, SUP.host) == 0)
|
flags = ((strcmp (host, SUP.host) == 0)
|
||||||
&& (strcmp (user, SUP.user) == 0) && (flags == SUP.flags));
|
&& (strcmp (user, SUP.user) == 0) && (flags == SUP.flags));
|
||||||
g_free (host);
|
mhl_mem_free (host);
|
||||||
g_free (user);
|
mhl_mem_free (user);
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
|||||||
char buffer[8192];
|
char buffer[8192];
|
||||||
struct vfs_s_entry *ent = NULL;
|
struct vfs_s_entry *ent = NULL;
|
||||||
FILE *logfile;
|
FILE *logfile;
|
||||||
char *quoted_path;
|
SHELL_ESCAPED_STR quoted_path;
|
||||||
int reply_code;
|
int reply_code;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -453,8 +453,8 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
|||||||
"else\n"
|
"else\n"
|
||||||
"echo '### 500'\n"
|
"echo '### 500'\n"
|
||||||
"fi\n",
|
"fi\n",
|
||||||
quoted_path, quoted_path, quoted_path, quoted_path, quoted_path, quoted_path);
|
quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s);
|
||||||
mhl_mem_free (quoted_path);
|
mhl_mem_free (quoted_path.s);
|
||||||
ent = vfs_s_generate_entry(me, NULL, dir, 0);
|
ent = vfs_s_generate_entry(me, NULL, dir, 0);
|
||||||
while (1) {
|
while (1) {
|
||||||
int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr);
|
int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr);
|
||||||
@ -585,7 +585,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
|||||||
vfs_s_free_entry (me, ent);
|
vfs_s_free_entry (me, ent);
|
||||||
reply_code = fish_decode_reply(buffer + 4, 0);
|
reply_code = fish_decode_reply(buffer + 4, 0);
|
||||||
if (reply_code == COMPLETE) {
|
if (reply_code == COMPLETE) {
|
||||||
g_free (SUP.cwdir);
|
mhl_mem_free (SUP.cwdir);
|
||||||
SUP.cwdir = g_strdup (remote_path);
|
SUP.cwdir = g_strdup (remote_path);
|
||||||
print_vfs_message (_("%s: done."), me->name);
|
print_vfs_message (_("%s: done."), me->name);
|
||||||
return 0;
|
return 0;
|
||||||
@ -609,7 +609,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
|
|||||||
struct stat s;
|
struct stat s;
|
||||||
int was_error = 0;
|
int was_error = 0;
|
||||||
int h;
|
int h;
|
||||||
char *quoted_name;
|
SHELL_ESCAPED_STR quoted_name;
|
||||||
|
|
||||||
h = open (localname, O_RDONLY);
|
h = open (localname, O_RDONLY);
|
||||||
|
|
||||||
@ -650,7 +650,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
quoted_name = mhl_shell_escape_dup(name);
|
quoted_name = mhl_shell_escape_dup(name);
|
||||||
print_vfs_message(_("fish: store %s: sending command..."), quoted_name );
|
print_vfs_message(_("fish: store %s: sending command..."), quoted_name.s );
|
||||||
|
|
||||||
/* FIXME: File size is limited to ULONG_MAX */
|
/* FIXME: File size is limited to ULONG_MAX */
|
||||||
if (!fh->u.fish.append)
|
if (!fh->u.fish.append)
|
||||||
@ -674,8 +674,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
|
|||||||
" rest=`expr $rest - $n`\n"
|
" rest=`expr $rest - $n`\n"
|
||||||
"done\n"
|
"done\n"
|
||||||
"}; echo '### 200'\n",
|
"}; echo '### 200'\n",
|
||||||
(unsigned long) s.st_size, quoted_name,
|
(unsigned long) s.st_size, quoted_name.s,
|
||||||
quoted_name, (unsigned long) s.st_size,
|
quoted_name.s, (unsigned long) s.st_size,
|
||||||
(unsigned long) s.st_size);
|
(unsigned long) s.st_size);
|
||||||
else
|
else
|
||||||
n = fish_command (me, super, WAIT_REPLY,
|
n = fish_command (me, super, WAIT_REPLY,
|
||||||
@ -691,8 +691,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
|
|||||||
" rest=`expr $rest - $n`\n"
|
" rest=`expr $rest - $n`\n"
|
||||||
"done\n"
|
"done\n"
|
||||||
"}; echo '### 200'\n",
|
"}; echo '### 200'\n",
|
||||||
(unsigned long) s.st_size, quoted_name,
|
(unsigned long) s.st_size, quoted_name.s,
|
||||||
quoted_name, (unsigned long) s.st_size);
|
quoted_name.s, (unsigned long) s.st_size);
|
||||||
|
|
||||||
if (n != PRELIM) {
|
if (n != PRELIM) {
|
||||||
close (h);
|
close (h);
|
||||||
@ -726,14 +726,14 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
|
|||||||
(unsigned long) s.st_size);
|
(unsigned long) s.st_size);
|
||||||
}
|
}
|
||||||
close(h);
|
close(h);
|
||||||
mhl_mem_free(quoted_name);
|
mhl_mem_free(quoted_name.s);
|
||||||
if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
|
if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
|
||||||
ERRNOR (E_REMOTE, -1);
|
ERRNOR (E_REMOTE, -1);
|
||||||
return 0;
|
return 0;
|
||||||
error_return:
|
error_return:
|
||||||
close(h);
|
close(h);
|
||||||
fish_get_reply(me, SUP.sockr, NULL, 0);
|
fish_get_reply(me, SUP.sockr, NULL, 0);
|
||||||
mhl_mem_free(quoted_name);
|
mhl_mem_free(quoted_name.s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +741,7 @@ static int
|
|||||||
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
char *quoted_name;
|
SHELL_ESCAPED_STR quoted_name;
|
||||||
if (offset)
|
if (offset)
|
||||||
ERRNOR (E_NOTSUPP, 0);
|
ERRNOR (E_NOTSUPP, 0);
|
||||||
name = vfs_s_fullpath (me, fh->ino);
|
name = vfs_s_fullpath (me, fh->ino);
|
||||||
@ -770,8 +770,8 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
|||||||
"else\n"
|
"else\n"
|
||||||
"echo '### 500'\n"
|
"echo '### 500'\n"
|
||||||
"fi\n",
|
"fi\n",
|
||||||
quoted_name, quoted_name, quoted_name, quoted_name );
|
quoted_name.s, quoted_name.s, quoted_name.s, quoted_name.s );
|
||||||
g_free (quoted_name);
|
mhl_mem_free (quoted_name.s);
|
||||||
if (offset != PRELIM) ERRNOR (E_REMOTE, 0);
|
if (offset != PRELIM) ERRNOR (E_REMOTE, 0);
|
||||||
fh->linear = LS_LINEAR_OPEN;
|
fh->linear = LS_LINEAR_OPEN;
|
||||||
fh->u.fish.got = 0;
|
fh->u.fish.got = 0;
|
||||||
@ -880,17 +880,18 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c
|
|||||||
#define PREFIX \
|
#define PREFIX \
|
||||||
char buf[BUF_LARGE]; \
|
char buf[BUF_LARGE]; \
|
||||||
const char *crpath; \
|
const char *crpath; \
|
||||||
char *rpath, *mpath = g_strdup (path); \
|
char *mpath = mhl_str_dup (path); \
|
||||||
|
SHELL_ESCAPED_STR rpath; \
|
||||||
struct vfs_s_super *super; \
|
struct vfs_s_super *super; \
|
||||||
if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \
|
if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \
|
||||||
g_free (mpath); \
|
mhl_mem_free (mpath); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
rpath = mhl_shell_escape_dup(crpath); \
|
rpath = mhl_shell_escape_dup(crpath); \
|
||||||
g_free (mpath);
|
mhl_mem_free (mpath);
|
||||||
|
|
||||||
#define POSTFIX(flags) \
|
#define POSTFIX(flags) \
|
||||||
g_free (rpath); \
|
mhl_mem_free (rpath.s); \
|
||||||
return fish_send_command(me, super, buf, flags);
|
return fish_send_command(me, super, buf, flags);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -910,24 +911,24 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat
|
|||||||
{ \
|
{ \
|
||||||
char buf[BUF_LARGE]; \
|
char buf[BUF_LARGE]; \
|
||||||
const char *crpath1, *crpath2; \
|
const char *crpath1, *crpath2; \
|
||||||
char *rpath1, *rpath2, *mpath1, *mpath2; \
|
char *mpath1, *mpath2; \
|
||||||
struct vfs_s_super *super1, *super2; \
|
struct vfs_s_super *super1, *super2; \
|
||||||
if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \
|
if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \
|
||||||
g_free (mpath1); \
|
mhl_mem_free (mpath1); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \
|
if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \
|
||||||
g_free (mpath1); \
|
mhl_mem_free (mpath1); \
|
||||||
g_free (mpath2); \
|
mhl_mem_free (mpath2); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
rpath1 = mhl_shell_escape_dup (crpath1); \
|
SHELL_ESCAPED_STR rpath1 = mhl_shell_escape_dup (crpath1); \
|
||||||
g_free (mpath1); \
|
mhl_mem_free (mpath1); \
|
||||||
rpath2 = mhl_shell_escape_dup (crpath2); \
|
SHELL_ESCAPED_STR rpath2 = mhl_shell_escape_dup (crpath2); \
|
||||||
g_free (mpath2); \
|
mhl_mem_free (mpath2); \
|
||||||
g_snprintf(buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \
|
g_snprintf(buf, sizeof(buf), string "\n", rpath1.s, rpath2.s, rpath1.s, rpath2.s); \
|
||||||
mhl_mem_free (rpath1); \
|
mhl_mem_free (rpath1.s); \
|
||||||
mhl_mem_free (rpath2); \
|
mhl_mem_free (rpath2.s); \
|
||||||
return fish_send_command(me, super2, buf, OPT_FLUSH); \
|
return fish_send_command(me, super2, buf, OPT_FLUSH); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -940,7 +941,7 @@ FISH_OP(link, "#LINK /%s /%s\n"
|
|||||||
|
|
||||||
static int fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
static int fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
||||||
{
|
{
|
||||||
char *qsetto;
|
SHELL_ESCAPED_STR qsetto;
|
||||||
PREFIX
|
PREFIX
|
||||||
qsetto = mhl_shell_escape_dup (setto);
|
qsetto = mhl_shell_escape_dup (setto);
|
||||||
g_snprintf(buf, sizeof(buf),
|
g_snprintf(buf, sizeof(buf),
|
||||||
@ -948,7 +949,7 @@ static int fish_symlink (struct vfs_class *me, const char *setto, const char *pa
|
|||||||
"ln -s %s /%s 2>/dev/null\n"
|
"ln -s %s /%s 2>/dev/null\n"
|
||||||
"echo '### 000'\n",
|
"echo '### 000'\n",
|
||||||
qsetto, rpath, qsetto, rpath);
|
qsetto, rpath, qsetto, rpath);
|
||||||
mhl_mem_free (qsetto);
|
mhl_mem_free (qsetto.s);
|
||||||
POSTFIX(OPT_FLUSH);
|
POSTFIX(OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1078,7 +1079,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func)
|
|||||||
name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags,
|
name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags,
|
||||||
"/", SUP.cwdir, (char *) NULL);
|
"/", SUP.cwdir, (char *) NULL);
|
||||||
(*func)(name);
|
(*func)(name);
|
||||||
g_free (name);
|
mhl_mem_free (name);
|
||||||
super = super->next;
|
super = super->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user