Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/distrib/utils/sysinst Make url_decode() return a pointer to ...
details: https://anonhg.NetBSD.org/src/rev/a2697d9f1c8f
branches: trunk
changeset: 571154:a2697d9f1c8f
user: dsl <dsl%NetBSD.org@localhost>
date: Thu Nov 11 21:36:23 2004 +0000
description:
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.
diffstat:
distrib/utils/sysinst/net.c | 49 +++++++++++++++++++++-----------------------
1 files changed, 23 insertions(+), 26 deletions(-)
diffs (104 lines):
diff -r 4e4400e85f96 -r a2697d9f1c8f distrib/utils/sysinst/net.c
--- a/distrib/utils/sysinst/net.c Thu Nov 11 21:24:40 2004 +0000
+++ b/distrib/utils/sysinst/net.c Thu Nov 11 21:36:23 2004 +0000
@@ -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.
@@ -86,7 +86,7 @@
/* 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,
int encode_leading_slash);
@@ -172,35 +172,35 @@
#define RFC1738_SAFE_LESS_SHELL_PLUS_SLASH "-_.+!,/"
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)
{
- char *p = dst;
- char *ep = dst + len;
int ch;
- for (; ep - p > 1; src++) {
+ ep--;
+
+ for (; dst < ep; src++) {
ch = *src & 0xff;
if (ch == 0)
break;
if (safe_chars != NULL &&
(ch != '/' || !encode_leading_slash) &&
(isalnum(ch) || strchr(safe_chars, ch))) {
- *p++ = ch;
+ *dst++ = ch;
} else {
/* encode this char */
- if (ep - p < 3)
+ if (ep - dst < 3)
break;
- snprintf(p, ep - p, "%%%02X", ch);
- p += 3;
+ snprintf(dst, ep - dst, "%%%02X", ch);
+ dst += 3;
}
encode_leading_slash = 0;
}
-done:
- *p = '\0';
+ *dst = '\0';
return dst;
}
+
static const char *ignored_if_names[] = {
"eon", /* netiso */
"gre", /* net */
@@ -804,28 +804,25 @@
ftp_user_encoded[0] = 0;
} else {
ftp_opt = "";
- url_encode(ftp_user_encoded, ftp_user,
- sizeof ftp_user_encoded / 2 - 1,
- RFC1738_SAFE_LESS_SHELL, 0),
- cp = strchr(ftp_user_encoded, 0);
+ cp = url_encode(ftp_user_encoded, ftp_user,
+ ftp_user_encoded + sizeof ftp_user_encoded - 1,
+ RFC1738_SAFE_LESS_SHELL, 0);
*cp++ = ':';
- url_encode(cp, ftp_pass,
- sizeof ftp_user_encoded / 2 - 1,
- NULL, 0),
- cp = strchr(cp, 0);
+ cp = url_encode(cp, ftp_pass,
+ ftp_user_encoded + sizeof ftp_user_encoded - 1,
+ NULL, 0);
*cp++ = '@';
*cp = 0;
}
- url_encode(ftp_dir_encoded, ftp_dir,
- sizeof ftp_dir_encoded - 1,
- RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1),
- cp = strchr(ftp_dir_encoded, 0);
+ cp = url_encode(ftp_dir_encoded, ftp_dir,
+ ftp_dir_encoded + sizeof ftp_dir_encoded - 1,
+ RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 1);
if (set_dir[0] != '/')
*cp++ = '/';
url_encode(cp, set_dir,
- ftp_dir_encoded + sizeof ftp_dir_encoded - cp,
- RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0),
+ ftp_dir_encoded + sizeof ftp_dir_encoded,
+ RFC1738_SAFE_LESS_SHELL_PLUS_SLASH, 0);
ret = run_program(RUN_DISPLAY | RUN_PROGRESS,
"/usr/bin/ftp %s%s://%s%s/%s/%s%s",
Home |
Main Index |
Thread Index |
Old Index