From 6cc6d5d2620524668d1bfd5fa74b799ab786303d Mon Sep 17 00:00:00 2001 From: lukem Date: Sun, 7 Feb 1999 13:14:06 +0000 Subject: [PATCH] changes to fix [bin/6951] by Peter Simons : * 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(). --- usr.bin/ftp/complete.c | 15 ++++++++------- usr.bin/ftp/extern.h | 3 ++- usr.bin/ftp/util.c | 36 ++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/usr.bin/ftp/complete.c b/usr.bin/ftp/complete.c index 1ba90b2514b4..076fd2a35f84 100644 --- a/usr.bin/ftp/complete.c +++ b/usr.bin/ftp/complete.c @@ -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 #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); diff --git a/usr.bin/ftp/extern.h b/usr.bin/ftp/extern.h index 3faa1d6a39f2..e01bf6630a14 100644 --- a/usr.bin/ftp/extern.h +++ b/usr.bin/ftp/extern.h @@ -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 *)); diff --git a/usr.bin/ftp/util.c b/usr.bin/ftp/util.c index 16f9ae9a7a1d..b9055baee872 100644 --- a/usr.bin/ftp/util.c +++ b/usr.bin/ftp/util.c @@ -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 #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. */