From: jongfoster Date: Tue, 23 Oct 2001 21:38:53 +0000 (+0000) Subject: Adding error-checking to create_url_spec() X-Git-Tag: v_2_9_10~92 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=e7776e41d6c7706ad53ae5b3dee1c03ea05aec97 Adding error-checking to create_url_spec() --- diff --git a/loaders.c b/loaders.c index d800ed83..7843fc4c 100644 --- a/loaders.c +++ b/loaders.c @@ -1,4 +1,4 @@ -const char loaders_rcs[] = "$Id: loaders.c,v 1.27 2001/09/22 16:36:59 jongfoster Exp $"; +const char loaders_rcs[] = "$Id: loaders.c,v 1.28 2001/10/07 15:40:39 oes Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.c,v $ @@ -35,6 +35,9 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.27 2001/09/22 16:36:59 jongfoster * * Revisions : * $Log: loaders.c,v $ + * Revision 1.28 2001/10/07 15:40:39 oes + * Replaced 6 boolean members of csp with one bitmap (csp->flags) + * * Revision 1.27 2001/09/22 16:36:59 jongfoster * Removing unused parameter fs from read_config_line() * @@ -184,6 +187,7 @@ const char loaders_rcs[] = "$Id: loaders.c,v 1.27 2001/09/22 16:36:59 jongfoster #include #include #include +#include #ifndef _WIN32 #include @@ -369,24 +373,24 @@ void sweep(void) * function fails, the contents of the buffer * are lost forever. * - * Returns : 0 => Ok, everything else is an error. + * Returns : JB_ERR_OK - Success + * JB_ERR_MEMORY - Out of memory + * JB_ERR_PARSE - Cannot parse regex (Detailed message + * written to system log) * *********************************************************************/ -int create_url_spec(struct url_spec * url, char * buf) +jb_err create_url_spec(struct url_spec * url, char * buf) { char *p; struct url_spec tmp_url[1]; - /* paranoia - should never happen. */ - if ((url == NULL) || (buf == NULL)) - { - return 1; - } + assert(url); + assert(buf); /* save a copy of the orignal specification */ if ((url->spec = strdup(buf)) == NULL) { - return 1; + return JB_ERR_MEMORY; } if ((p = strchr(buf, '/'))) @@ -394,7 +398,7 @@ int create_url_spec(struct url_spec * url, char * buf) if (NULL == (url->path = strdup(p))) { freez(url->spec); - return 1; + return JB_ERR_MEMORY; } url->pathlen = strlen(url->path); *p = '\0'; @@ -414,7 +418,7 @@ int create_url_spec(struct url_spec * url, char * buf) { freez(url->spec); freez(url->path); - return 1; + return JB_ERR_MEMORY; } sprintf(rebuf, "^(%s)", url->path); @@ -424,18 +428,22 @@ int create_url_spec(struct url_spec * url, char * buf) if (errcode) { size_t errlen = regerror(errcode, - url->preg, buf, sizeof(buf)); + url->preg, rebuf, sizeof(rebuf)); - buf[errlen] = '\0'; + if (errlen > (sizeof(rebuf) - (size_t)1)) + { + errlen = sizeof(rebuf) - (size_t)1; + } + rebuf[errlen] = '\0'; log_error(LOG_LEVEL_ERROR, "error compiling %s: %s", - url->spec, buf); + url->spec, rebuf); freez(url->spec); freez(url->path); freez(url->preg); - return 1; + return JB_ERR_PARSE; } } #endif @@ -456,18 +464,29 @@ int create_url_spec(struct url_spec * url, char * buf) #ifdef REGEX freez(url->preg); #endif /* def REGEX */ - return 1; + return JB_ERR_MEMORY; } /* split domain into components */ *tmp_url = dsplit(url->domain); + if (tmp_url->dbuf == NULL) + { + freez(url->spec); + freez(url->path); + freez(url->domain); +#ifdef REGEX + freez(url->preg); +#endif /* def REGEX */ + return JB_ERR_MEMORY; + } + url->dbuf = tmp_url->dbuf; url->dcnt = tmp_url->dcnt; url->dvec = tmp_url->dvec; url->unanchored = tmp_url->unanchored; - return 0; /* OK */ + return JB_ERR_OK; } diff --git a/loaders.h b/loaders.h index a0fea3e9..c4955e39 100644 --- a/loaders.h +++ b/loaders.h @@ -1,6 +1,6 @@ #ifndef LOADERS_H_INCLUDED #define LOADERS_H_INCLUDED -#define LOADERS_H_VERSION "$Id: loaders.h,v 1.9 2001/07/30 22:08:36 jongfoster Exp $" +#define LOADERS_H_VERSION "$Id: loaders.h,v 1.10 2001/09/22 16:36:59 jongfoster Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loaders.h,v $ @@ -37,6 +37,9 @@ * * Revisions : * $Log: loaders.h,v $ + * Revision 1.10 2001/09/22 16:36:59 jongfoster + * Removing unused parameter fs from read_config_line() + * * Revision 1.9 2001/07/30 22:08:36 jongfoster * Tidying up #defines: * - All feature #defines are now of the form FEATURE_xxx @@ -133,7 +136,7 @@ extern int load_trustfile(struct client_state *csp); -extern int create_url_spec(struct url_spec * url, char * buf); +extern jb_err create_url_spec(struct url_spec * url, char * buf); extern void free_url(struct url_spec *url); extern void add_loader(int (*loader)(struct client_state *),