Make url_decode() return a pointer to the end of the string, and take a
char * limit (not a length) to simplify buffer overrun avoidance.
This commit is contained in:
parent
7d6407147b
commit
e4ad2fc0f8
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: net.c,v 1.103 2004/11/11 21:24:41 dsl Exp $ */
|
/* $NetBSD: net.c,v 1.104 2004/11/11 21:36:23 dsl Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1997 Piermont Information Systems Inc.
|
* Copyright 1997 Piermont Information Systems Inc.
|
||||||
@ -86,7 +86,7 @@ static int net_ip6conf;
|
|||||||
|
|
||||||
/* URL encode unsafe characters. */
|
/* URL encode unsafe characters. */
|
||||||
|
|
||||||
static char *url_encode (char *dst, const char *src, size_t len,
|
static char *url_encode (char *dst, const char *src, const char *ep,
|
||||||
const char *safe_chars,
|
const char *safe_chars,
|
||||||
int encode_leading_slash);
|
int encode_leading_slash);
|
||||||
|
|
||||||
@ -172,35 +172,35 @@ static int get_v6wait (void);
|
|||||||
#define RFC1738_SAFE_LESS_SHELL_PLUS_SLASH "-_.+!,/"
|
#define RFC1738_SAFE_LESS_SHELL_PLUS_SLASH "-_.+!,/"
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
url_encode(char *dst, const char *src, size_t len,
|
url_encode(char *dst, const char *src, const char *ep,
|
||||||
const char *safe_chars, int encode_leading_slash)
|
const char *safe_chars, int encode_leading_slash)
|
||||||
{
|
{
|
||||||
char *p = dst;
|
|
||||||
char *ep = dst + len;
|
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
for (; ep - p > 1; src++) {
|
ep--;
|
||||||
|
|
||||||
|
for (; dst < ep; src++) {
|
||||||
ch = *src & 0xff;
|
ch = *src & 0xff;
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
break;
|
break;
|
||||||
if (safe_chars != NULL &&
|
if (safe_chars != NULL &&
|
||||||
(ch != '/' || !encode_leading_slash) &&
|
(ch != '/' || !encode_leading_slash) &&
|
||||||
(isalnum(ch) || strchr(safe_chars, ch))) {
|
(isalnum(ch) || strchr(safe_chars, ch))) {
|
||||||
*p++ = ch;
|
*dst++ = ch;
|
||||||
} else {
|
} else {
|
||||||
/* encode this char */
|
/* encode this char */
|
||||||
if (ep - p < 3)
|
if (ep - dst < 3)
|
||||||
break;
|
break;
|
||||||
snprintf(p, ep - p, "%%%02X", ch);
|
snprintf(dst, ep - dst, "%%%02X", ch);
|
||||||
p += 3;
|
dst += 3;
|
||||||
}
|
}
|
||||||
encode_leading_slash = 0;
|
encode_leading_slash = 0;
|
||||||
}
|
}
|
||||||
done:
|
*dst = '\0';
|
||||||
*p = '\0';
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *ignored_if_names[] = {
|
static const char *ignored_if_names[] = {
|
||||||
"eon", /* netiso */
|
"eon", /* netiso */
|
||||||
"gre", /* net */
|
"gre", /* net */
|
||||||
@ -804,28 +804,25 @@ get_via_ftp(const char *xfer_type)
|
|||||||
ftp_user_encoded[0] = 0;
|
ftp_user_encoded[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
ftp_opt = "";
|
ftp_opt = "";
|
||||||
url_encode(ftp_user_encoded, ftp_user,
|
cp = url_encode(ftp_user_encoded, ftp_user,
|
||||||
sizeof ftp_user_encoded / 2 - 1,
|
ftp_user_encoded + sizeof ftp_user_encoded - 1,
|
||||||
RFC1738_SAFE_LESS_SHELL, 0),
|
RFC1738_SAFE_LESS_SHELL, 0);
|
||||||
cp = strchr(ftp_user_encoded, 0);
|
|
||||||
*cp++ = ':';
|
*cp++ = ':';
|
||||||
url_encode(cp, ftp_pass,
|
cp = url_encode(cp, ftp_pass,
|
||||||
sizeof ftp_user_encoded / 2 - 1,
|
ftp_user_encoded + sizeof ftp_user_encoded - 1,
|
||||||
NULL, 0),
|
NULL, 0);
|
||||||
cp = strchr(cp, 0);
|
|
||||||
*cp++ = '@';
|
*cp++ = '@';
|
||||||
*cp = 0;
|
*cp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
url_encode(ftp_dir_encoded, ftp_dir,
|
cp = url_encode(ftp_dir_encoded, ftp_dir,
|
||||||
sizeof ftp_dir_encoded - 1,
|
ftp_dir_encoded + sizeof ftp_dir_encoded - 1,
|
||||||
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
|
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1);
|
||||||
cp = strchr(ftp_dir_encoded, 0);
|
|
||||||
if (set_dir[0] != '/')
|
if (set_dir[0] != '/')
|
||||||
*cp++ = '/';
|
*cp++ = '/';
|
||||||
url_encode(cp, set_dir,
|
url_encode(cp, set_dir,
|
||||||
ftp_dir_encoded + sizeof ftp_dir_encoded - cp,
|
ftp_dir_encoded + sizeof ftp_dir_encoded,
|
||||||
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0),
|
RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0);
|
||||||
|
|
||||||
ret = run_program(RUN_DISPLAY | RUN_PROGRESS,
|
ret = run_program(RUN_DISPLAY | RUN_PROGRESS,
|
||||||
"/usr/bin/ftp %s%s://%s%s/%s/%s%s",
|
"/usr/bin/ftp %s%s://%s%s/%s/%s%s",
|
||||||
|
Loading…
Reference in New Issue
Block a user