You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Graham Clark <gc...@dcs.ed.ac.uk> on 2003/07/09 21:05:21 UTC
bug in ApacheRequest_parse macro
Hi,
There seems to be a minor bug in apache_request.h when a dereferenced
argument is supplied to this macro - how about the following simple
patch? (Hope I've checked the latest version!)
Graham
--- apache_request.h 2003-02-27 15:03:58.000000000 -0500
+++ apache_request.h-new 2003-07-09 14:53:08.000000000 -0500
@@ -97,7 +97,7 @@
char *ApacheRequest_params_as_string(ApacheRequest *req, const char *key);
int ApacheRequest___parse(ApacheRequest *req);
#define ApacheRequest_parse(req) \
- (req->status = req->parsed ? req->status : ApacheRequest___parse(req))
+ ((req)->status = (req)->parsed ? (req)->status : ApacheRequest___parse(req))
table *ApacheRequest_query_params(ApacheRequest *req, ap_pool *p);
table *ApacheRequest_post_params(ApacheRequest *req, ap_pool *p);
Re: bug in ApacheRequest_parse macro
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Graham Clark <gc...@dcs.ed.ac.uk> writes:
> Hi again,
>
> Thanks for all the info Joe! Would there be any interest in
> incorporating the following patches too? My aim was to provide a way
> to get the parameter keys only.
Thanks for the patches! However I don't think we should have "keys"
functions in libapreq-1 for query & body params. Do we already have
"keys" for "normal" params- (not a rhetorical question, I haven't looked
at the libapreq-1 source in a while)?
> I'm not yet sure of the philosophy of apreq,
^^^^^^^^^^^^^^^^^^^
I'd say the "apreq philosophy" is something like:
1) safe, (secure defaults, no misbehavior with bad data)
2) standards-compliant, (plus occasional browser work-arounds for
better interoperability)
3) simple, (a small, easy-to-use library interface)
4) speedy, (minimize copying & internal pool allocations)
with the relative importance being roughly in that order.
> so if this is overkill, or there's an easier way to do this, I'd be
> glad to know :-)
I'd probably vote against the "keys" patches as being overkill:
AFAICT there's not much need for this functionality in libapreq
right now.
--
Joe Schaefer
Re: bug in ApacheRequest_parse macro
Posted by Graham Clark <gc...@dcs.ed.ac.uk>.
Hi again,
Thanks for all the info Joe! Would there be any interest in
incorporating the following patches too? My aim was to provide a way
to get the parameter keys only. I'm not yet sure of the philosophy of
apreq, so if this is overkill, or there's an easier way to do this,
I'd be glad to know :-)
Graham
Index: apache_request.h
===================================================================
RCS file: /home/cvspublic/httpd-apreq/c/apache_request.h,v
retrieving revision 1.11
diff -u -r1.11 apache_request.h
--- apache_request.h 10 Jul 2003 11:08:50 -0000 1.11
+++ apache_request.h 10 Jul 2003 18:56:26 -0000
@@ -100,6 +100,8 @@
((req)->status = (req)->parsed ? (req)->status : ApacheRequest___parse(req))
table *ApacheRequest_query_params(ApacheRequest *req, ap_pool *p);
table *ApacheRequest_post_params(ApacheRequest *req, ap_pool *p);
+array_header *ApacheRequest_query_keys(ApacheRequest *req);
+array_header *ApacheRequest_post_keys(ApacheRequest *req);
FILE *ApacheRequest_tmpfile(ApacheRequest *req, ApacheUpload *upload);
ApacheUpload *ApacheUpload_new(ApacheRequest *req);
Index: apache_request.c
===================================================================
RCS file: /home/cvspublic/httpd-apreq/c/apache_request.c,v
retrieving revision 1.25
diff -u -r1.25 apache_request.c
--- apache_request.c 30 Apr 2003 14:53:09 -0000 1.25
+++ apache_request.c 10 Jul 2003 18:56:20 -0000
@@ -193,6 +193,33 @@
return (table *)a;
}
+static int make_keys(void *data, const char *key, const char *val)
+{
+ array_header *arr = (array_header *)data;
+ *(char **)ap_push_array(arr) = (char *)key;
+ return 1;
+}
+
+array_header *ApacheRequest_query_keys(ApacheRequest *req)
+{
+ table *queryparams;
+ array_header *values = ap_make_array(req->r->pool, 4, sizeof(char *));
+ ApacheRequest_parse(req);
+ queryparams = ApacheRequest_query_params(req, req->r->pool);
+ ap_table_do(make_keys, (void*)values, queryparams, NULL, NULL);
+ return values;
+}
+
+array_header *ApacheRequest_post_keys(ApacheRequest *req)
+{
+ table *postparams;
+ array_header *values = ap_make_array(req->r->pool, 4, sizeof(char *));
+ ApacheRequest_parse(req);
+ postparams = ApacheRequest_post_params(req, req->r->pool);
+ ap_table_do(make_keys, (void*)values, postparams, NULL, NULL);
+ return values;
+}
+
ApacheUpload *ApacheUpload_new(ApacheRequest *req)
{
ApacheUpload *upload = (ApacheUpload *)
Re: bug in ApacheRequest_parse macro
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Graham Clark <gc...@dcs.ed.ac.uk> writes:
[...]
> Here's an update. It compiles, but is untested (but then again, the
> changes are trivial).
Thanks!
> By the way, I had a look at the web site, but I'm uncertain what the
> best way to contribute changes is.
Emailing the output of
% cvs diff
to apreq-dev is probably the most common approach.
> Is there a CVS repository, or are changes vetted by the apreq team?
Both, I suppose. Access to the public cvs repository should be decribed
at the bottom of the httpd.apache.org/apreq/ webpage. Being a subproject
of Apache's httpd server, we follow their guidelines regarding code
contributions, committership, etc.
> Should patches be posted to this list?
Absolutely. There are two active repositories for apreq:
httpd-apreq and httpd-apreq-2, the latter of which is a
totally new design of libapreq based on apr and httpd-2.
--
Joe Schaefer
Re: bug in ApacheRequest_parse macro
Posted by Graham Clark <gc...@dcs.ed.ac.uk>.
> Thanks! So the bug is caused by the missing parens for req,
> right? Hmm, what about the other #define's in apache_request.h?
> Shouldn't we fix those also?
Oops, I was so lazy I didn't look! Sorry.
Here's an update. It compiles, but is untested (but then again, the
changes are trivial).
By the way, I had a look at the web site, but I'm uncertain what the
best way to contribute changes is. Is there a CVS repository, or are
changes vetted by the apreq team? Should patches be posted to this
list?
Thanks,
Graham
--- apache_request.h-orig 2003-07-09 22:32:01.000000000 -0500
+++ apache_request.h 2003-07-09 22:33:12.000000000 -0500
@@ -60,19 +60,19 @@
};
#ifndef strEQ
-#define strEQ(s1,s2) (!strcmp(s1,s2))
+#define strEQ(s1,s2) (!strcmp((s1),(s2)))
#endif
#ifndef strEQN
-#define strEQN(s1,s2,n) (!strncmp(s1,s2,n))
+#define strEQN(s1,s2,n) (!strncmp((s1),(s2),(n)))
#endif
#ifndef strcaseEQ
-#define strcaseEQ(s1,s2) (!strcasecmp(s1,s2))
+#define strcaseEQ(s1,s2) (!strcasecmp((s1),(s2)))
#endif
#ifndef strncaseEQ
-#define strncaseEQ(s1,s2,n) (!strncasecmp(s1,s2,n))
+#define strncaseEQ(s1,s2,n) (!strncasecmp((s1),(s2),(n)))
#endif
#define DEFAULT_TABLE_NELTS 10
@@ -97,7 +97,7 @@
char *ApacheRequest_params_as_string(ApacheRequest *req, const char *key);
int ApacheRequest___parse(ApacheRequest *req);
#define ApacheRequest_parse(req) \
- (req->status = req->parsed ? req->status : ApacheRequest___parse(req))
+ ((req)->status = (req)->parsed ? (req)->status : ApacheRequest___parse(req))
table *ApacheRequest_query_params(ApacheRequest *req, ap_pool *p);
table *ApacheRequest_post_params(ApacheRequest *req, ap_pool *p);
@@ -106,20 +106,20 @@
ApacheUpload *ApacheUpload_find(ApacheUpload *upload, char *name);
#define ApacheRequest_upload(req) \
- ((req->parsed || (ApacheRequest_parse(req) == OK)) ? req->upload : NULL)
+ (((req)->parsed || (ApacheRequest_parse(req) == OK)) ? (req)->upload : NULL)
-#define ApacheUpload_FILE(upload) (upload->fp)
+#define ApacheUpload_FILE(upload) ((upload)->fp)
-#define ApacheUpload_size(upload) (upload->size)
+#define ApacheUpload_size(upload) ((upload)->size)
#define ApacheUpload_info(upload, key) \
-ap_table_get(upload->info, key)
+ap_table_get((upload)->info, (key))
#define ApacheUpload_type(upload) \
-ApacheUpload_info(upload, "Content-Type")
+ApacheUpload_info((upload), "Content-Type")
-#define ApacheRequest_set_post_max(req, max) (req->post_max = max)
-#define ApacheRequest_set_temp_dir(req, dir) (req->temp_dir = dir)
+#define ApacheRequest_set_post_max(req, max) ((req)->post_max = (max))
+#define ApacheRequest_set_temp_dir(req, dir) ((req)->temp_dir = (dir))
char *ApacheUtil_expires(pool *p, char *time_str, int type);
#define EXPIRES_HTTP 1
@@ -133,7 +133,7 @@
#define REQ_ERROR APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, req->r
#ifdef REQDEBUG
-#define REQ_DEBUG(a) a
+#define REQ_DEBUG(a) (a)
#else
#define REQ_DEBUG(a)
#endif
Re: bug in ApacheRequest_parse macro
Posted by Joe Schaefer <jo...@sunstarsys.com>.
Graham Clark <gc...@dcs.ed.ac.uk> writes:
> Hi,
>
> There seems to be a minor bug in apache_request.h when a dereferenced
> argument is supplied to this macro - how about the following simple
> patch? (Hope I've checked the latest version!)
[...]
> #define ApacheRequest_parse(req) \
> - (req->status = req->parsed ? req->status : ApacheRequest___parse(req))
> + ((req)->status = (req)->parsed ? (req)->status : \
> + ApacheRequest___parse(req))
Thanks! So the bug is caused by the missing parens for req,
right? Hmm, what about the other #define's in apache_request.h?
Shouldn't we fix those also?
--
Joe Schaefer