[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev Re: resolving weird URL types (patch)
From: |
Leonid Pauzner |
Subject: |
lynx-dev Re: resolving weird URL types (patch) |
Date: |
Thu, 13 May 1999 16:49:42 +0400 (MSD) |
13-May-99 14:58 I wrote:
> Example: press 'g' and enter xyz://aaa.bbb.cc URL.
> Apparently, lynx will not reject weird URL schemes
> at LYEnsureAbsoluteURL() / LYConvertURL() stage,
> it will try to resolve DNS first.
> Such URL prefixes normally rejected by is_url() in getfile()
> with "Badly formed address" alert message
> but user defined URLs (startfile, etc.) does serve another way.
> Lynx Trace Log (2.8.2pre.3)
> User message: Trace ON!
> 'xyz://aaa.bbb.cc' is not a URL
> Converted 'xyz://aaa.bbb.cc' to 'c:/lynx/dist28/pre3/xyz://aaa.bbb.cc'
> Can't stat() or fopen() 'c:/lynx/dist28/pre3/xyz://aaa.bbb.cc'
> Looking up xyz: first.
> In fact, there are two unsupported url types:
> one without "://" so guessing is possible
> and the other with unsupported prefix before "://" string (no guessing),
> but is_url() use a single UNKNOWN_URL_TYPE.
> IMO, LYEnsureAbsoluteURL() should filter out such urls itself.
The patch:
* avoid URL guessing (LYConvertToURL() calls) when URL has '://' string
and unsupported prefix.
* LYFillLocalFileURL() moved from LYCharUtils.c to LYUtils.c
(where all such functions located).
* cosmetic changes in getfile().
diff -u old/lycharut.c ./lycharut.c
--- old/lycharut.c Wed May 5 17:34:00 1999
+++ ./lycharut.c Thu May 13 15:07:24 1999
@@ -294,112 +294,6 @@
}
/*
-** If an HREF, itself or if resolved against a base,
-** represents a file URL, and the host is defaulted,
-** force in "//localhost". We need this until
-** all the other Lynx code which performs security
-** checks based on the "localhost" string is changed
-** to assume "//localhost" when a host field is not
-** present in file URLs - FM
-*/
-PUBLIC void LYFillLocalFileURL ARGS2(
- char **, href,
- CONST char *, base)
-{
- char * temp = NULL;
-
- if (*href == NULL || *(*href) == '\0')
- return;
-
- if (!strcmp(*href, "//") || !strncmp(*href, "///", 3)) {
- if (base != NULL && !strncmp(base, "file:", 5)) {
- StrAllocCopy(temp, "file:");
- StrAllocCat(temp, *href);
- StrAllocCopy(*href, temp);
- }
- }
- if (!strncmp(*href, "file:", 5)) {
- if (*(*href+5) == '\0') {
- StrAllocCat(*href, "//localhost");
- } else if (!strcmp(*href, "file://")) {
- StrAllocCat(*href, "localhost");
- } else if (!strncmp(*href, "file:///", 8)) {
- StrAllocCopy(temp, (*href+7));
- LYLocalFileToURL (href, temp);
- } else if (!strncmp(*href, "file:/", 6) && !LYIsHtmlSep(*(*href+6))) {
- StrAllocCopy(temp, (*href+5));
- LYLocalFileToURL (href, temp);
- }
- }
-
-#if defined(DOSPATH) || defined(__EMX__)
- if (isalpha(*(*href)) && (*(*href+1) == ':')) {
- /*
- * If it's a local DOS path beginning with drive letter,
- * add file://localhost/ prefix and go ahead.
- */
- StrAllocCopy(temp, *href);
- LYLocalFileToURL (href, temp);
- }
-
- /* use below: strlen("file://localhost/") = 17 */
- if (!strncmp(*href, "file://localhost/", 17)
- && (strlen(*href) == 19)
- && isalpha(*(*href+17))
- && (*(*href+18) == ':')) {
- /*
- * Terminate DOS drive letter with a slash to surf root successfully.
- * Here seems a proper place to do so.
- */
- StrAllocCat(*href, "/");
- }
-#endif /* DOSPATH */
-
- /*
- * No path in a file://localhost URL means a
- * directory listing for the current default. - FM
- */
- if (!strcmp(*href, "file://localhost")) {
- char *temp2;
-#ifdef VMS
- temp2 = HTVMS_wwwName(getenv("PATH"));
-#else
- char curdir[LY_MAXPATH];
-#if HAVE_GETCWD
- getcwd (curdir, sizeof(curdir));
-#else
- getwd (curdir);
-#endif /* NO_GETCWD */
- temp2 = wwwName(curdir);
-#endif /* VMS */
- LYAddHtmlSep(href);
- /*
- * Check for pathological cases - current dir has chars which
- * MUST BE URL-escaped - kw
- */
- if (strchr(temp2, '%') != NULL || strchr(temp2, '#') != NULL) {
- FREE(temp);
- temp = HTEscape(temp2, URL_PATH);
- StrAllocCat(*href, temp);
- } else {
- StrAllocCat(*href, temp2);
- }
- }
-
-#ifdef VMS
- /*
- * On VMS, a file://localhost/ URL means
- * a listing for the login directory. - FM
- */
- if (!strcmp(*href, "file://localhost/"))
- StrAllocCat(*href, (HTVMS_wwwName((char *)Home_Dir())+1));
-#endif /* VMS */
-
- FREE(temp);
- return;
-}
-
-/*
** This function writes a line with a META tag to an open file,
** which will specify a charset parameter to use when the file is
** read back in. It is meant for temporary HTML files used by the
diff -u old/lycharut.h ./lycharut.h
--- old/lycharut.h Fri Jul 24 20:01:04 1998
+++ ./lycharut.h Thu May 13 15:08:06 1999
@@ -36,9 +36,6 @@
char * str));
extern char *LYFindEndOfComment PARAMS((
char * str));
-extern void LYFillLocalFileURL PARAMS((
- char ** href,
- CONST char * base));
extern void LYAddMETAcharsetToFD PARAMS((
FILE * fd,
int disp_chndl));
diff -u old/lygetfil.c ./lygetfil.c
--- old/lygetfil.c Wed May 5 17:34:00 1999
+++ ./lygetfil.c Thu May 13 13:10:22 1999
@@ -140,11 +140,19 @@
*
* Some special URL's we handle ourselves. :)
*/
- if ((url_type = is_url(doc->address)) != 0) {
+ if ((url_type = is_url(doc->address)) == 0) {
+ CTRACE_SLEEP(MessageSecs);
+ HTUserMsg2(WWW_BAD_ADDR_MESSAGE, doc->address);
+ CTRACE(tfp,"\n");
+ return(NULLFILE);
+ } else {
+ /* url_type recognized, do all the checks: */
+
if (LYValidate && !LYPermitURL) {
if (!(url_type == HTTP_URL_TYPE ||
url_type == HTTPS_URL_TYPE ||
url_type == LYNXHIST_URL_TYPE ||
+ /* registered with LYRegisterLynxProtocols() in
LYMain.c: */
url_type == LYNXKEYMAP_URL_TYPE ||
url_type == LYNXIMGMAP_URL_TYPE ||
url_type == LYNXCOOKIE_URL_TYPE ||
@@ -181,6 +189,7 @@
url_type == LYNXOPTIONS_URL_TYPE ||
url_type == LYNXCFG_URL_TYPE ||
url_type == LYNXCOMPILE_OPTS_URL_TYPE ||
+ url_type == LYNXMESSAGES_URL_TYPE ||
url_type == LYNXDOWNLOAD_URL_TYPE ||
url_type == MAILTO_URL_TYPE ||
url_type == NEWSPOST_URL_TYPE ||
@@ -474,6 +483,7 @@
*/
} else if (local_host_only &&
url_type != NEWS_URL_TYPE &&
+ /* any LYNXfoo:/ URL not handled above is allowed */
url_type != LYNXKEYMAP_URL_TYPE &&
url_type != LYNXIMGMAP_URL_TYPE &&
url_type != LYNXCOOKIE_URL_TYPE &&
@@ -726,6 +736,7 @@
url_type == LYNXOPTIONS_URL_TYPE ||
url_type == LYNXCFG_URL_TYPE ||
url_type == LYNXCOMPILE_OPTS_URL_TYPE ||
+ url_type == LYNXMESSAGES_URL_TYPE ||
url_type == LYNXHIST_URL_TYPE ||
url_type == LYNXCOOKIE_URL_TYPE ||
(LYValidate &&
@@ -932,12 +943,7 @@
}
}
}
- } else {
- CTRACE_SLEEP(MessageSecs);
- HTUserMsg2(WWW_BAD_ADDR_MESSAGE, doc->address);
- CTRACE(tfp,"\n");
- return(NULLFILE);
- }
+ } /* url_type handled */
}
/*
diff -u old/lyutils.c ./lyutils.c
--- old/lyutils.c Sat May 8 10:46:28 1999
+++ ./lyutils.c Thu May 13 16:26:20 1999
@@ -3782,6 +3782,112 @@
#endif /* VMS */
/*
+** If an HREF, itself or if resolved against a base,
+** represents a file URL, and the host is defaulted,
+** force in "//localhost". We need this until
+** all the other Lynx code which performs security
+** checks based on the "localhost" string is changed
+** to assume "//localhost" when a host field is not
+** present in file URLs - FM
+*/
+PUBLIC void LYFillLocalFileURL ARGS2(
+ char **, href,
+ CONST char *, base)
+{
+ char * temp = NULL;
+
+ if (*href == NULL || *(*href) == '\0')
+ return;
+
+ if (!strcmp(*href, "//") || !strncmp(*href, "///", 3)) {
+ if (base != NULL && !strncmp(base, "file:", 5)) {
+ StrAllocCopy(temp, "file:");
+ StrAllocCat(temp, *href);
+ StrAllocCopy(*href, temp);
+ }
+ }
+ if (!strncmp(*href, "file:", 5)) {
+ if (*(*href+5) == '\0') {
+ StrAllocCat(*href, "//localhost");
+ } else if (!strcmp(*href, "file://")) {
+ StrAllocCat(*href, "localhost");
+ } else if (!strncmp(*href, "file:///", 8)) {
+ StrAllocCopy(temp, (*href+7));
+ LYLocalFileToURL (href, temp);
+ } else if (!strncmp(*href, "file:/", 6) && !LYIsHtmlSep(*(*href+6))) {
+ StrAllocCopy(temp, (*href+5));
+ LYLocalFileToURL (href, temp);
+ }
+ }
+
+#if defined(DOSPATH) || defined(__EMX__)
+ if (isalpha(*(*href)) && (*(*href+1) == ':')) {
+ /*
+ * If it's a local DOS path beginning with drive letter,
+ * add file://localhost/ prefix and go ahead.
+ */
+ StrAllocCopy(temp, *href);
+ LYLocalFileToURL (href, temp);
+ }
+
+ /* use below: strlen("file://localhost/") = 17 */
+ if (!strncmp(*href, "file://localhost/", 17)
+ && (strlen(*href) == 19)
+ && isalpha(*(*href+17))
+ && (*(*href+18) == ':')) {
+ /*
+ * Terminate DOS drive letter with a slash to surf root successfully.
+ * Here seems a proper place to do so.
+ */
+ StrAllocCat(*href, "/");
+ }
+#endif /* DOSPATH */
+
+ /*
+ * No path in a file://localhost URL means a
+ * directory listing for the current default. - FM
+ */
+ if (!strcmp(*href, "file://localhost")) {
+ char *temp2;
+#ifdef VMS
+ temp2 = HTVMS_wwwName(getenv("PATH"));
+#else
+ char curdir[LY_MAXPATH];
+#if HAVE_GETCWD
+ getcwd (curdir, sizeof(curdir));
+#else
+ getwd (curdir);
+#endif /* NO_GETCWD */
+ temp2 = wwwName(curdir);
+#endif /* VMS */
+ LYAddHtmlSep(href);
+ /*
+ * Check for pathological cases - current dir has chars which
+ * MUST BE URL-escaped - kw
+ */
+ if (strchr(temp2, '%') != NULL || strchr(temp2, '#') != NULL) {
+ FREE(temp);
+ temp = HTEscape(temp2, URL_PATH);
+ StrAllocCat(*href, temp);
+ } else {
+ StrAllocCat(*href, temp2);
+ }
+ }
+
+#ifdef VMS
+ /*
+ * On VMS, a file://localhost/ URL means
+ * a listing for the login directory. - FM
+ */
+ if (!strcmp(*href, "file://localhost/"))
+ StrAllocCat(*href, (HTVMS_wwwName((char *)Home_Dir())+1));
+#endif /* VMS */
+
+ FREE(temp);
+ return;
+}
+
+/*
** This function ensures that an href will be
** converted to a fully resolved, absolute URL,
** with guessing of the host or expansions of
@@ -3812,7 +3918,22 @@
if (!is_url(*href)) {
CTRACE(tfp, "%s%s'%s' is not a URL\n",
(name ? name : ""), (name ? " " : ""), *href);
- LYConvertToURL(href);
+ if (strstr(*href, "://") != NULL) {
+ /*
+ * Weird prefix before "://" - no guessing possible.
+ * Drop trace message and fall down to getfile() silently: small
+ * overhead but does not require LYMain.c/LYMainLoop.c coding.
+ */
+ CTRACE(tfp, " unsupported URL prefix before '://' %s\n",
+ "- no recovery (sleep till getfile warning)");
+ /* this warning will be issued from getfile() stage:
+ CTRACE_SLEEP(MessageSecs);
+ HTUserMsg2(WWW_BAD_ADDR_MESSAGE, doc->address);
+ CTRACE(tfp,"\n");
+ */
+ } else {
+ LYConvertToURL(href);
+ }
}
if ((temp = HTParse(*href, "", PARSE_ALL)) != NULL && *temp != '\0')
StrAllocCopy(*href, temp);
@@ -3824,6 +3945,8 @@
* as a file URL if the string resolves to a file or
* directory on the local system, otherwise as an
* http URL. - FM
+ *
+ * Called by LYEnsureAbsoluteURL() only.
*/
PUBLIC void LYConvertToURL ARGS1(
char **, AllocatedString)
diff -u old/lyutils.h ./lyutils.h
--- old/lyutils.h Wed May 5 17:34:00 1999
+++ ./lyutils.h Thu May 13 16:15:10 1999
@@ -100,6 +100,7 @@
extern void LYCloseTempFP PARAMS((FILE *fp));
extern void LYConvertToURL PARAMS((char **AllocatedString));
extern void LYDoCSI PARAMS((char *url, CONST char *comment, char **csi));
+extern void LYFillLocalFileURL PARAMS((char **href, CONST char *base));
extern void LYEnsureAbsoluteURL PARAMS((char **href, CONST char *name));
extern void LYFakeZap PARAMS((BOOL set));
extern void LYLocalFileToURL PARAMS((char **target, CONST char *source));
- lynx-dev Re: resolving weird URL types (patch),
Leonid Pauzner <=
- Re: lynx-dev Re: resolving weird URL types, Philip Webb, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, John Bley, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, Leonid Pauzner, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, Philip Webb, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, pg, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, mattack, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, Philip Webb, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, pg, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, mattack, 1999/05/13
- Re: lynx-dev Re: resolving weird URL types, Philip Webb, 1999/05/13