From c298ea4ab70f9143a5f87eb103ca29eeb4377845 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 27 Apr 2000 18:24:13 +0000 Subject: [PATCH] * setup.c (findhref): Return NULL on empty string. Eat any trailing ";something". (processdirlisting): Attempt to limit recursively processing the same directory. --- ChangeLog | 7 +++++ setup.c | 90 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c432b6f..8d55054a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Apr 27 14:21:30 2000 Christopher Faylor + + * setup.c (findhref): Return NULL on empty string. Eat any trailing + ";something". + (processdirlisting): Attempt to limit recursively processing the same + directory. + Thu Apr 27 11:42:23 2000 Christopher Faylor * setup.c (filedel): New function. diff --git a/setup.c b/setup.c index db191581..c664d28f 100644 --- a/setup.c +++ b/setup.c @@ -660,8 +660,14 @@ findhref (char *buffer, char *date, size_t *filesize) { char *ref = NULL; char *anchor; - char *p = buffer; - + char *p; + int eatspace; + char *q; + char digits[20]; + char *diglast = digits + sizeof (digits) - 1; + int len; + + p = buffer; while ((p = strchr (p, '<')) != NULL) { char *q = p; @@ -684,44 +690,45 @@ findhref (char *buffer, char *date, size_t *filesize) } } - if (ref) - { - int eatspace; - char *p, *q; - char digits[20]; - char *diglast = digits + sizeof (digits) - 1; - int len; - - ref += ref[5] == '"' ? 6 : 5; - - len = strcspn (ref, "\" >"); - - ref[len] = '\0'; - if (!filesize) - return ref; - - *filesize = 0; - - if (anchor == buffer || !isspace (anchor[-1])) - return ref; - - eatspace = 1; - *diglast = '\0'; - for (p = anchor, q = diglast; --p >= buffer; ) - if (!isspace (*p)) - { - eatspace = 0; - if (isdigit (*p)) - *--q = *p; - } - else if (!eatspace) - break; - - if (q < diglast) - *filesize = atoi (q); - } + if (!ref) + return NULL; + + ref += ref[5] == '"' ? 6 : 5; + + len = strcspn (ref, "\" >"); + + ref[len] = '\0'; + if (!filesize) + goto out; - return ref; + *filesize = 0; + + if (anchor == buffer || !isspace (anchor[-1])) + goto out; + + eatspace = 1; + *diglast = '\0'; + for (p = anchor, q = diglast; --p >= buffer; ) + if (!isspace (*p)) + { + eatspace = 0; + if (isdigit (*p)) + *--q = *p; + } + else if (!eatspace) + break; + + if (q < diglast) + *filesize = atoi (q); + +out: + if (!*ref) + return NULL; + /* This effectively disallows using a ';' in a file name. Hopefully, + this will not be an issue. */ + if ((p = strrchr (ref, ';')) != NULL) + *p = '\0'; + return *ref ? ref : NULL; } static int @@ -738,8 +745,9 @@ static int processdirlisting (const char *urlbase, const char *file) { int retval = 0; - char buffer[256]; + char buffer[4096]; static enum {UNKNOWN, ALWAYS, NEVER} download_when = {UNKNOWN}; + size_t urllen = strlen (urlbase); FILE *in = fopen (file, "rt"); @@ -762,6 +770,8 @@ processdirlisting (const char *urlbase, const char *file) warning ("Unable to download from %s", ref); winerror (); } + else if (strlen (url) == urllen || strnicmp (urlbase, url, urllen) != 0) + continue; else if (ref[strlen (ref) - 1] == '/') { if (strcmp (url + strlen (url) - 2, "./") != 0) -- 2.43.5