=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.52 retrieving revision 1.53 diff -c -r1.52 -r1.53 *** src/usr.bin/ftp/fetch.c 2005/04/05 22:37:00 1.52 --- src/usr.bin/ftp/fetch.c 2005/04/11 15:16:50 1.53 *************** *** 1,4 **** ! /* $OpenBSD: fetch.c,v 1.52 2005/04/05 22:37:00 henning Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: fetch.c,v 1.53 2005/04/11 15:16:50 deraadt Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- *************** *** 38,44 **** */ #if !defined(lint) && !defined(SMALL) ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.52 2005/04/05 22:37:00 henning Exp $"; #endif /* not lint and not SMALL */ /* --- 38,44 ---- */ #if !defined(lint) && !defined(SMALL) ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.53 2005/04/11 15:16:50 deraadt Exp $"; #endif /* not lint and not SMALL */ /* *************** *** 86,92 **** #define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) static const char *at_encoding_warning = ! "Extra `@' characters in usernames and passwords should be encoded as %%40"; jmp_buf httpabort; --- 86,92 ---- #define EMPTYSTRING(x) ((x) == NULL || (*(x) == '\0')) static const char *at_encoding_warning = ! "Extra `@' characters in usernames and passwords should be encoded as %%40"; jmp_buf httpabort; *************** *** 98,129 **** static int url_get(const char *origline, const char *proxyenv, const char *outfile) { struct addrinfo hints, *res0, *res; - int error; - int i, isftpurl, isfileurl, isredirect; - volatile int s, out; - size_t len; - char *cp, *ep, *portnum, *path; - char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST]; const char * volatile savefile; ! char *line, *host, *port, *buf; ! char * volatile proxy; ! char *hosttail; volatile sig_t oldintr; off_t hashbytes; ! char *cause = "unknown"; ! FILE *fin; ! int rval; - s = -1; - proxy = NULL; - fin = NULL; - buf = NULL; - isftpurl = 0; - isfileurl = 0; - isredirect = 0; - rval = -1; - line = strdup(origline); if (line == NULL) errx(1, "Can't allocate memory to parse URL"); --- 98,115 ---- static int url_get(const char *origline, const char *proxyenv, const char *outfile) { + char pbuf[NI_MAXSERV], hbuf[NI_MAXHOST], *cp, *ep, *portnum, *path; + char *hosttail, *cause = "unknown", *line, *host, *port, *buf = NULL; + int error, i, isftpurl = 0, isfileurl = 0, isredirect = 0, rval = -1; struct addrinfo hints, *res0, *res; const char * volatile savefile; ! char * volatile proxy = NULL; ! volatile int s = -1, out; volatile sig_t oldintr; + FILE *fin = NULL; off_t hashbytes; ! size_t len; line = strdup(origline); if (line == NULL) errx(1, "Can't allocate memory to parse URL"); *************** *** 873,926 **** char * urldecode(const char *str) { ! char *ret; ! char c; ! int i, reallen; ! if (str == NULL) ! return NULL; ! if ((ret = malloc(strlen(str)+1)) == NULL) ! err(1, "Can't allocate memory for URL decoding"); ! for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { ! c = str[i]; ! if (c == '+') { ! *ret = ' '; ! continue; ! } ! /* Can't use strtol here because next char after %xx may be ! * a digit. */ ! if (c == '%' && isxdigit(str[i+1]) && isxdigit(str[i+2])) { ! *ret = hextochar(&str[i+1]); ! i+=2; ! continue; ! } ! *ret = c; ! } ! *ret = '\0'; ! return ret-reallen; } char hextochar(const char *str) { ! char c, ret; ! c = str[0]; ! ret = c; ! if (isalpha(c)) ! ret -= isupper(c) ? 'A' - 10 : 'a' - 10; ! else ! ret -= '0'; ! ret *= 16; ! c = str[1]; ! ret += c; ! if (isalpha(c)) ! ret -= isupper(c) ? 'A' - 10 : 'a' - 10; ! else ! ret -= '0'; ! return ret; } int --- 859,911 ---- char * urldecode(const char *str) { ! char *ret, c; ! int i, reallen; ! if (str == NULL) ! return NULL; ! if ((ret = malloc(strlen(str)+1)) == NULL) ! err(1, "Can't allocate memory for URL decoding"); ! for (i = 0, reallen = 0; str[i] != '\0'; i++, reallen++, ret++) { ! c = str[i]; ! if (c == '+') { ! *ret = ' '; ! continue; ! } ! /* Can't use strtol here because next char after %xx may be ! * a digit. */ ! if (c == '%' && isxdigit(str[i+1]) && isxdigit(str[i+2])) { ! *ret = hextochar(&str[i+1]); ! i+=2; ! continue; ! } ! *ret = c; ! } ! *ret = '\0'; ! return ret-reallen; } char hextochar(const char *str) { ! char c, ret; ! c = str[0]; ! ret = c; ! if (isalpha(c)) ! ret -= isupper(c) ? 'A' - 10 : 'a' - 10; ! else ! ret -= '0'; ! ret *= 16; ! c = str[1]; ! ret += c; ! if (isalpha(c)) ! ret -= isupper(c) ? 'A' - 10 : 'a' - 10; ! else ! ret -= '0'; ! return ret; } int