changes to fix [bin/6951] by Peter Simons <simons@cys.de>:

* implement ftpvis(), which \ quotes the following in the given string:
  SP, TAB, \, CR, "
* use ftpvis() in complete_ambiguous(), to escape characters in a word
  which would confuse makeargv()/slurpstring().
This commit is contained in:
lukem 1999-02-07 13:14:06 +00:00
parent b8ebb2ba4e
commit 6cc6d5d262
3 changed files with 42 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: complete.c,v 1.17 1999/02/07 12:27:50 lukem Exp $ */
/* $NetBSD: complete.c,v 1.18 1999/02/07 13:14:06 lukem Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: complete.c,v 1.17 1999/02/07 12:27:50 lukem Exp $");
__RCSID("$NetBSD: complete.c,v 1.18 1999/02/07 13:14:06 lukem Exp $");
#endif /* not lint */
/*
@ -98,8 +98,9 @@ complete_ambiguous(word, list, words)
return (CC_ERROR); /* no choices available */
if (words->sl_cur == 1) { /* only once choice available */
(void)strcpy(insertstr, words->sl_str[0]);
if (el_insertstr(el, insertstr + wordlen) == -1)
char *p = words->sl_str[0] + wordlen;
ftpvis(insertstr, sizeof(insertstr), p, strlen(p));
if (el_insertstr(el, insertstr) == -1)
return (CC_ERROR);
else
return (CC_REFRESH);
@ -117,9 +118,9 @@ complete_ambiguous(word, list, words)
matchlen = j;
}
if (matchlen > wordlen) {
(void)strncpy(insertstr, lastmatch, matchlen);
insertstr[matchlen] = '\0';
if (el_insertstr(el, insertstr + wordlen) == -1)
ftpvis(insertstr, sizeof(insertstr),
lastmatch + wordlen, matchlen);
if (el_insertstr(el, insertstr) == -1)
return (CC_ERROR);
else
return (CC_REFRESH_BEEP);

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.26 1998/11/18 07:24:26 itohy Exp $ */
/* $NetBSD: extern.h,v 1.27 1999/02/07 13:14:06 lukem Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -70,6 +70,7 @@ void doproxy __P((int, char **));
char *dotrans __P((char *));
int empty __P((struct fd_set *, int));
int foregroundproc __P((void));
void ftpvis __P((char *, size_t, const char *, size_t));
int ftp_login __P((const char *, const char *, const char *));
void get __P((int, char **));
struct cmd *getcmd __P((const char *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.42 1999/01/31 02:29:00 lukem Exp $ */
/* $NetBSD: util.c,v 1.43 1999/02/07 13:14:07 lukem Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: util.c,v 1.42 1999/01/31 02:29:00 lukem Exp $");
__RCSID("$NetBSD: util.c,v 1.43 1999/02/07 13:14:07 lukem Exp $");
#endif /* not lint */
/*
@ -499,8 +499,7 @@ globulize(cpp)
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
memset(&gl, 0, sizeof(gl));
if (glob(*cpp, flags, NULL, &gl) ||
gl.gl_pathc == 0) {
if (glob(*cpp, flags, NULL, &gl) || gl.gl_pathc == 0) {
warnx("%s: not found", *cpp);
globfree(&gl);
return (0);
@ -1188,6 +1187,35 @@ resetsockbufsize()
rcvbuf_size = 0;
}
void
ftpvis(dst, dstlen, src, srclen)
char *dst;
size_t dstlen;
const char *src;
size_t srclen;
{
int di, si;
for (di = si = 0;
src[si] != '\0' && di < dstlen && si < srclen;
di++, si++) {
switch (src[si]) {
case '\\':
case ' ':
case '\t':
case '\r':
case '"':
dst[di++] = '\\';
if (di >= dstlen)
break;
/* FALLTHROUGH */
default:
dst[di] = src[si];
}
}
dst[di] = '\0';
}
/*
* Internal version of connect(2); sets socket buffer sizes first.
*/