X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=pcrs.h;h=a3bfede6414c568b65a4be1811ea010f6abe8088;hp=4b22a1b83ea37c8bf1b72d57d56555af403d392d;hb=828afb5284f082722460ac443a958016b0f77a6f;hpb=390f0eb1b038295df436210c62aabb8243680a89 diff --git a/pcrs.h b/pcrs.h index 4b22a1b8..a3bfede6 100644 --- a/pcrs.h +++ b/pcrs.h @@ -11,6 +11,19 @@ * * Revisions : * $Log: pcrs.h,v $ + * Revision 1.15 2007/01/05 15:46:12 fabiankeil + * Don't use strlen() to calculate the length of + * the pcrs substitutes. They don't have to be valid C + * strings and getting their length wrong can result in + * user-controlled memory corruption. + * + * Thanks to Felix Gröbert for reporting the problem + * and providing the fix [#1627140]. + * + * Revision 1.14 2006/12/24 17:27:37 fabiankeil + * Increase pcrs error code offset to prevent overlaps + * with pcre versions newer than our own. + * * Revision 1.13 2006/07/18 14:48:47 david__schmidt * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch) * with what was really the latest development (the v_3_0_branch branch) @@ -66,7 +79,7 @@ * *********************************************************************/ -#define PCRS_H_VERSION "$Id: pcrs.h,v 1.13 2006/07/18 14:48:47 david__schmidt Exp $" +#define PCRS_H_VERSION "$Id: pcrs.h,v 1.15 2007/01/05 15:46:12 fabiankeil Exp $" #ifndef _PCRE_H @@ -98,11 +111,13 @@ extern "C" { * PCRE 6.7 uses error codes from -1 to -21, PCRS error codes * below -100 should be safe for a while. */ -#define PCRS_ERR_NOMEM -100 /* Failed to acquire memory. */ -#define PCRS_ERR_CMDSYNTAX -101 /* Syntax of s///-command */ -#define PCRS_ERR_STUDY -102 /* pcre error while studying the pattern */ -#define PCRS_ERR_BADJOB -103 /* NULL job pointer, pattern or substitute */ -#define PCRS_WARN_BADREF -104 /* Backreference out of range */ +#define PCRS_ERR_NOMEM -100 /* Failed to acquire memory. */ +#define PCRS_ERR_CMDSYNTAX -101 /* Syntax of s///-command */ +#define PCRS_ERR_STUDY -102 /* pcre error while studying the pattern */ +#define PCRS_ERR_BADJOB -103 /* NULL job pointer, pattern or substitute */ +#define PCRS_WARN_BADREF -104 /* Backreference out of range */ +#define PCRS_WARN_TRUNCATION -105 /* At least one pcrs variable was too big, + * only the first part was used. */ /* Flags */ #define PCRS_GLOBAL 1 /* Job should be applied globally, as with perl's g option */ @@ -118,6 +133,7 @@ extern "C" { typedef struct { char *text; /* The plaintext part of the substitute, with all backreferences stripped */ + size_t length; /* The substitute may not be a valid C string so we can't rely on strlen(). */ int backrefs; /* The number of backreferences */ int block_offset[PCRS_MAX_SUBMATCHES]; /* Array with the offsets of all plaintext blocks in text */ size_t block_length[PCRS_MAX_SUBMATCHES]; /* Array with the lengths of all plaintext blocks in text */ @@ -159,7 +175,7 @@ typedef struct PCRS_JOB { /* Main usage */ extern pcrs_job *pcrs_compile_command(const char *command, int *errptr); extern pcrs_job *pcrs_compile(const char *pattern, const char *substitute, const char *options, int *errptr); -extern int pcrs_execute(pcrs_job *job, char *subject, size_t subject_length, char **result, size_t *result_length); +extern int pcrs_execute(pcrs_job *job, const char *subject, size_t subject_length, char **result, size_t *result_length); extern int pcrs_execute_list(pcrs_job *joblist, char *subject, size_t subject_length, char **result, size_t *result_length); /* Freeing jobs */ @@ -169,6 +185,25 @@ extern void pcrs_free_joblist(pcrs_job *joblist); /* Info on errors: */ extern const char *pcrs_strerror(const int error); +extern int pcrs_job_is_dynamic(char *job); +extern char pcrs_get_delimiter(const char *string); +extern char *pcrs_execute_single_command(const char *subject, const char *pcrs_command, int *hits); +/* + * Variable/value pair for dynamic pcrs commands. + */ +struct pcrs_variable +{ + const char *name; + char *value; + int static_value; +}; + +extern pcrs_job *pcrs_compile_dynamic_command(char *pcrs_command, const struct pcrs_variable v[], int *error); + +/* Only relevant for maximum pcrs variable size */ +#ifndef PCRS_BUFFER_SIZE +#define PCRS_BUFFER_SIZE 4000 +#endif /* ndef PCRS_BUFFER_SIZE */ #ifdef __cplusplus } /* extern "C" */