merge master into uploadcmdfix
diff --git a/ChangeLog b/ChangeLog
index a851367..381c7c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-03 Massimo Manghi <mxmanghi@apache.org>
+ * src/request/: Update obsolete copyright statements
+ * src/mod_rivet_ng/rivetCore.c: update comments to upload command
+ * tests: changed upload file test
+
2020-04-02 Massimo Manghi <mxmanghi@apache.org>
* doc/xml/formbroker.xml: fixed examples
* src/mod_rivet_ng/rivet_lazy_mpm.c: resolved access to shared counter
@@ -6,13 +11,26 @@
2020-01-19 Massimo Manghi <mxmanghi@apache.org>
* doc/xml/commands.xml: remove entry for command incr0 (dropped in 3.0)
+2019-12-30 Massimo Manghi <mxmanghi@apache.org>
+ * src/mod_rivet_ng/rivetCore.c: fixed bug in 'upload filename' that
+ caused segfaults instead of Tcl errors when called without arguments
+ * src/request/: Adding latest Copyright statements to files in this
+ directory
+ * tests/upload.rvt,upload.test: revised upload tests (need expansion
+ to test multiple uploads)
+
2019-12-12 Massimo Manghi <mxmanghi@apache.org>
* src/mod_rivet_ng/apache_config.c: copying also upload_files_to_var in
Rivet_MergeConfig
2019-12-06 Massimo Manghi <mxmanghi@apache.org>
+ * src/mod_rivet_ng/rivetCore.c: expanded error info data in Rivet_Upload
* doc/rivet.css: new color scheme for docbook manual
+2019-12-04 Massimo Manghi <mxmanghi@apache.org>
+ * src/mod_rivet_ng/rivetCore.c: new branch uploadcmdfix with improved
+ argument checking in Rivet_Upload that was the cause of random crashes
+
2019-11-29 Brice Hamon <bhdec@apache.org>
* src/mod_rivet_ng/mod_rivet_cache.h: added RivetCache_DeleteEntry
* src/mod_rivet_ng/mod_rivet_cache.c:
diff --git a/STATUS b/STATUS
index fc24cc1..bacea17 100644
--- a/STATUS
+++ b/STATUS
@@ -20,7 +20,7 @@
-------- ----------- ---
Debian Tcl 8.6 Yes
Ubuntu Tcl 8.6 Yes
-CentOS Tcl 8.6 Yes
-Suse Tcl 8.6 Yes
+CentOS Tcl 8.6 Yes
+Suse Tcl 8.6 Yes
FreeBSD Tcl 8.6 Yes
Windows 10 Tcl 8.6 Yes
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 2446072..98c90d5 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -19,8 +19,6 @@
under the License.
*/
-/* $Id$ */
-
/* Rivet config */
#ifdef HAVE_CONFIG_H
@@ -656,28 +654,26 @@
{
req->upload = ApacheUpload_find(req->apachereq->upload, varname);
if (req->upload == NULL) {
- return TCL_ERROR;
+ return TCL_ERROR;
} else {
- return TCL_OK;
+ return TCL_OK;
}
}
int TclWeb_UploadChannel(char *varname, Tcl_Channel *chan, TclWebRequest *req)
{
- *chan = Tcl_OpenFileChannel (req->interp, req->upload->tempname, "r", 0);
+ *chan = Tcl_OpenFileChannel(req->interp, req->upload->tempname, "r", 0);
if (chan == NULL) {
- return TCL_ERROR;
+ return TCL_ERROR;
} else {
- if (Tcl_SetChannelOption(req->interp, *chan,
- "-translation", "binary") == TCL_ERROR) {
- return TCL_ERROR;
- }
- if (Tcl_SetChannelOption(req->interp, *chan,
- "-encoding", "binary") == TCL_ERROR) {
- return TCL_ERROR;
- }
- Tcl_RegisterChannel (req->interp, *chan);
- return TCL_OK;
+ if (Tcl_SetChannelOption(req->interp,*chan,"-translation","binary") == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ if (Tcl_SetChannelOption(req->interp,*chan,"-encoding","binary") == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ Tcl_RegisterChannel(req->interp, *chan);
+ return TCL_OK;
}
}
@@ -766,10 +762,10 @@
upload = ApacheRequest_upload(req->apachereq);
while (upload)
{
- Tcl_ListObjAppendElement(
- req->interp, names,
- TclWeb_StringToUtfToObj(upload->name,req));
- upload = upload->next;
+ Tcl_ListObjAppendElement(
+ req->interp, names,
+ TclWeb_StringToUtfToObj(upload->name,req));
+ upload = upload->next;
}
return TCL_OK;
diff --git a/src/mod_rivet_ng/mod_rivet.c b/src/mod_rivet_ng/mod_rivet.c
index d3dbc5c..91550eb 100644
--- a/src/mod_rivet_ng/mod_rivet.c
+++ b/src/mod_rivet_ng/mod_rivet.c
@@ -327,7 +327,7 @@
apr_pool_userdata_set((const void *)1, userdata_key,
apr_pool_cleanup_null, server->process->pool);
- ap_log_error(APLOG_MARK,APLOG_INFO,0,server,
+ ap_log_error(APLOG_MARK,APLOG_DEBUG,0,server,
"first post_config run: not initializing Tcl stuff");
return OK; /* This would be the first time through */
diff --git a/src/mod_rivet_ng/mod_rivet.h b/src/mod_rivet_ng/mod_rivet.h
index 88f9b8a..2a43998 100644
--- a/src/mod_rivet_ng/mod_rivet.h
+++ b/src/mod_rivet_ng/mod_rivet.h
@@ -227,7 +227,7 @@
request_rec* r; /* current request_rec */
TclWebRequest* req;
//Tcl_Obj* request_init;
- Tcl_Obj* request_cleanup;
+ //Tcl_Obj* request_cleanup;
rivet_server_conf* running_conf; /* running configuration */
running_scripts* running; /* (per request) running conf scripts */
int thread_exit; /* Thread exit code */
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index b67a016..ff9abba 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -1023,16 +1023,7 @@
*
* Rivet_Upload --
*
- * Deals with file uploads (multipart/form-data) like so:
- *
- * upload channel uploadname
- * upload save name uploadname
- * upload data uploadname
- * upload exists uploadname
- * upload size uploadname
- * upload type uploadname
- * upload filename uploadname
- * upload names
+ * Deals with file uploads (multipart/form-data):
*
* Results:
* A standard Tcl result.
@@ -1048,9 +1039,34 @@
{
char* varname = NULL;
int subcommandindex;
+ int upload_prepared = 0;
Tcl_Obj* result = NULL;
+ /* ::rivet::upload subcommands must register
+ *
+ * - subcommand definition
+ * - subcommand integer progressive index
+ * - subcommand required (minimum) number of arguments
+ *
+ * +----------------------------------------+-------+
+ * | argv[1] argv[2] argv[3] | argc |
+ * +----------------------------------------+-------+
+ * | upload channel uploadname | 3 |
+ * | upload save uploadname filename | 4 |
+ * | upload data uploadname | 3 |
+ * | upload exists uploadname | 3 |
+ * | upload size uploadname | 3 |
+ * | upload type uploadname | 3 |
+ * | upload filename uploadname | 3 |
+ * | upload tempname uploadname | 3 |
+ * | upload names | 2 |
+ * +----------------------------------------+-------+
+ *
+ * a subcommand first optional argument must be the name
+ * of an upload
+ */
+
static CONST84 char *SubCommand[] = {
"channel",
"save",
@@ -1076,47 +1092,50 @@
NAMES
};
- rivet_thread_private* private;
+ static CONST84 int cmds_objc[] = { 3,4,3,3,3,3,3,3,2 };
+ int expected_objc;
+
+ rivet_thread_private* private;
THREAD_PRIVATE_DATA(private)
CHECK_REQUEST_REC(private,"::rivet::upload")
if (Tcl_GetIndexFromObj(interp, objv[1], SubCommand,
- "channel|save|data|exists|size|type|filename|names|tempname"
- "|tempname|names",
+ "channel|save|data|exists|size|type|filename|tempname|names",
0, &subcommandindex) == TCL_ERROR) {
return TCL_ERROR;
}
- /* If it's any of these, we need to find a specific name. */
+ expected_objc = cmds_objc[subcommandindex];
- /* Excluded case is NAMES. */
+ if (objc != expected_objc) {
+ Tcl_Obj* infoobj = Tcl_NewStringObj("Wrong argument numbers: ",-1);
- if ((enum subcommand)subcommandindex == CHANNEL ||
- (enum subcommand)subcommandindex == SAVE ||
- (enum subcommand)subcommandindex == DATA ||
- (enum subcommand)subcommandindex == EXISTS ||
- (enum subcommand)subcommandindex == SIZE ||
- (enum subcommand)subcommandindex == TYPE ||
- (enum subcommand)subcommandindex == FILENAME ||
- (enum subcommand)subcommandindex == TEMPNAME)
- {
+ Tcl_IncrRefCount(infoobj);
+ Tcl_AppendObjToObj(infoobj,Tcl_NewIntObj(expected_objc));
+ Tcl_AppendStringsToObj(infoobj," arguments expected");
+ Tcl_AppendObjToErrorInfo(interp, infoobj);
+ Tcl_DecrRefCount(infoobj);
+
+ Tcl_WrongNumArgs(interp, objc, objv, "uploadname");
+ return TCL_ERROR;
+ }
+
+ /* We check whether an upload with a given name exists */
+
+ if (objc >= 3) {
varname = Tcl_GetString(objv[2]);
- if ((enum subcommand)subcommandindex != EXISTS)
- {
- if (TclWeb_PrepareUpload(varname, private->req) != TCL_OK)
- {
- Tcl_AddErrorInfo(interp, "Unable to find variable");
- return TCL_ERROR;
- }
- }
- /* If it's not the 'save' command, then it has to have an objc
- of 3. */
- if ((enum subcommand)subcommandindex != SAVE && objc != 3)
+ /* TclWeb_PrepareUpload calls ApacheUpload_find and returns
+ * TCL_OK if the named upload exists in the current request */
+
+ if (TclWeb_PrepareUpload(varname, private->req) != TCL_OK)
{
- Tcl_WrongNumArgs(interp, 2, objv, "varname");
+ Tcl_AddErrorInfo(interp, "Unable to find the upload named '");
+ Tcl_AppendObjToErrorInfo(interp,Tcl_NewStringObj(varname,-1));
+ Tcl_AppendObjToErrorInfo(interp,Tcl_NewStringObj("'",-1));
return TCL_ERROR;
- }
+ }
+ upload_prepared = 1;
}
result = Tcl_NewObj();
@@ -1151,14 +1170,10 @@
return TCL_ERROR;
}
break;
- case EXISTS:
- if (TclWeb_PrepareUpload(varname, private->req) != TCL_OK)
- {
- Tcl_SetIntObj(result, 0);
- } else {
- Tcl_SetIntObj(result, 1);
- }
+ case EXISTS: {
+ Tcl_SetIntObj(result,upload_prepared);
break;
+ }
case SIZE:
TclWeb_UploadSize(result, private->req);
break;
diff --git a/src/mod_rivet_ng/rivet_types.h b/src/mod_rivet_ng/rivet_types.h
index 787a15f..6d24ff4 100644
--- a/src/mod_rivet_ng/rivet_types.h
+++ b/src/mod_rivet_ng/rivet_types.h
@@ -1,5 +1,5 @@
/* -- rivet_types.h: this file should collect all the basic types used
- * in mod_rivet and other related code
+ * in mod_rivet and other related code
*/
/*
@@ -21,10 +21,8 @@
under the License.
*/
-/* $Id$ */
-
-#ifndef __RIVET_TYPES_H__
-#define __RIVET_TYPES_H__
+#ifndef __rivet_types_h__
+#define __rivet_types_h__
#include <httpd.h>
#include <tcl.h>
@@ -76,7 +74,7 @@
int (*upload_hook)(void *ptr, char *buf, int len, ApacheUpload *upload);
void* hook_data;
const char* temp_dir;
- char* raw_post; /* Raw post data. */
+ char* raw_post; /* Raw post data. */
request_rec* r;
int nargs;
} ApacheRequest;
@@ -87,10 +85,11 @@
ApacheRequest* apachereq;
ApacheUpload* upload;
int headers_printed; /* has the header been printed yet? */
- int headers_set; /* has the header been set yet? */
+ int headers_set; /* has the header been set yet? */
int content_sent;
int environment_set; /* have we setup the environment variables? */
char* charset;
} TclWebRequest;
-#endif
+#endif /* __rivet_types_h__ */
+
diff --git a/src/request/apache_multipart_buffer.c b/src/request/apache_multipart_buffer.c
index 484b8f3..14a3ac9 100644
--- a/src/request/apache_multipart_buffer.c
+++ b/src/request/apache_multipart_buffer.c
@@ -1,16 +1,22 @@
-/* Copyright -2004 The Apache Software Foundation
+/* apache_multipart_buffer.c -- form multipart data handling */
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
/* Rivet config */
diff --git a/src/request/apache_multipart_buffer.h b/src/request/apache_multipart_buffer.h
index b899a46..6aa8662 100644
--- a/src/request/apache_multipart_buffer.h
+++ b/src/request/apache_multipart_buffer.h
@@ -1,22 +1,26 @@
-/* Copyright 2008 The Apache Software Foundation
+/* apache_multipart_buffer.h -- form multipart data handling */
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
-/* $Id$ */
-
-#ifndef _APACHE_MULTIPART_BUFFER_H
-#define _APACHE_MULTIPART_BUFFER_H
+#ifndef __apache_multipart_buffer_h__
+#define __apache_multipart_buffer_h__
#include "apache_request.h"
@@ -46,7 +50,7 @@
} multipart_buffer;
multipart_buffer* multipart_buffer_new(char* boundary,apr_off_t length,request_rec* r);
-///*table*/apr_table_t *multipart_buffer_headers(multipart_buffer *self);
+// /*table*/apr_table_t *multipart_buffer_headers(multipart_buffer *self);
size_t multipart_buffer_read(multipart_buffer* self,char* buf,size_t bytes);
char* multipart_buffer_read_body(multipart_buffer *self);
apr_table_t* multipart_buffer_headers(multipart_buffer *self);
@@ -56,4 +60,4 @@
}
#endif
-#endif
+#endif /*__apache_multipart_buffer_h__ */
diff --git a/src/request/apache_request.c b/src/request/apache_request.c
index b370273..7f7b4fb 100644
--- a/src/request/apache_request.c
+++ b/src/request/apache_request.c
@@ -1,16 +1,22 @@
-/* Copyright 2000-2004 The Apache Software Foundation
+/* apache_request.c -- Apache multipart form data handling */
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
+ http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
#include <errno.h>
@@ -564,9 +570,8 @@
#ifdef DEBUG
ap_log_rerror(REQ_ERROR,"Silently dropping remaining '%ld' bytes", r->remaining);
#endif
- do { } while ( ap_get_client_block(r, buff, sizeof(buff)) > 0 );
-
- return OK;
+ do { } while ( ap_get_client_block(r, buff, sizeof(buff)) > 0 );
+ return OK;
}
if ((cd = apr_table_get(header, "Content-Disposition"))) {
diff --git a/src/request/apache_request.h b/src/request/apache_request.h
index 22b8058..af84334 100644
--- a/src/request/apache_request.h
+++ b/src/request/apache_request.h
@@ -1,5 +1,26 @@
-#ifndef _APACHE_REQUEST_H
-#define _APACHE_REQUEST_H
+/* apache_request.h -- mod_rivet upload request functions */
+
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+#ifndef __apache_request_h__
+#define __apache_request_h__
#include "httpd.h"
#include "http_config.h"
@@ -93,11 +114,9 @@
#define ApacheUpload_size(upload) ((upload)->size)
-#define ApacheUpload_info(upload, key) \
-apr_table_get((upload)->info, (key))
+#define ApacheUpload_info(upload, key) apr_table_get((upload)->info, (key))
-#define ApacheUpload_type(upload) \
-ApacheUpload_info((upload), "Content-Type")
+#define ApacheUpload_type(upload) 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))
@@ -122,4 +141,4 @@
#define REQ_DEBUG(a)
#endif
-#endif /* _APACHE_REQUEST_H */
+#endif /* __apache_request_h__ */
diff --git a/tests/AngeloFish.png b/tests/AngeloFish.png
new file mode 100644
index 0000000..f43df9a
--- /dev/null
+++ b/tests/AngeloFish.png
Binary files differ
diff --git a/tests/runtests.tcl b/tests/runtests.tcl
index eaa9ee0..87ff358 100755
--- a/tests/runtests.tcl
+++ b/tests/runtests.tcl
@@ -16,8 +16,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# $Id$
-
set auto_path [linsert $auto_path 0 [file join [file dirname [info script]] apachetest]]
puts stderr "runtests.tcl is running with auto_path: $auto_path"
diff --git a/tests/upload.rvt b/tests/upload.rvt
index 5e84818..b9b5c40 100644
--- a/tests/upload.rvt
+++ b/tests/upload.rvt
@@ -1 +1,24 @@
-<? puts "[::rivet::upload names] [::rivet::upload exists uploadtest] [::rivet::upload size uploadtest] -[::rivet::upload type uploadtest]- [::rivet::upload filename uploadtest]" ?>
+<?
+ set names_res [catch { set up_names [::rivet::upload names] }]
+ set exists_res [catch { set up_exists [::rivet::upload exists uploadtest] }]
+ set size_res [catch { set up_size [::rivet::upload size uploadtest] }]
+ set type_res [catch { set up_type [::rivet::upload type uploadtest] }]
+ set filen_res [catch { set up_filen [::rivet::upload filename uploadtest] }]
+
+ if {$names_res || $exists_res || $size_res || $type_res || $filen_res } {
+ puts [join [list $names_res $exists_res $size_res $type_res $filen_res] "|"]
+ } else {
+ puts [join [list $up_names $up_exists $up_size $up_type $up_filen] "|"]
+ }
+
+
+ #if {[catch {
+ # puts [join [list [::rivet::upload names] \
+ # [::rivet::upload exists uploadtest] \
+ # [::rivet::upload size uploadtest] \
+ # [::rivet::upload type uploadtest] \
+ # [::rivet::upload filename uploadtest]] "|"]
+ # } e einfo]} {
+ # puts "Error $e: $einfo"
+ #}
+?>
diff --git a/tests/upload.test b/tests/upload.test
index 7b1ea9a..07ea699 100644
--- a/tests/upload.test
+++ b/tests/upload.test
@@ -1,4 +1,3 @@
-# $Id$
set testfilename1 upload.rvt
@@ -11,13 +10,12 @@
set outputData "--$bound\r\nContent-Disposition: form-data; name=\"uploadtest\"; filename=\"AngeloFish.jpg\"\r\n\r\n$data\n--${bound}--"
- set page [::http::geturl "${urlbase}$testfilename1" \
- -type "multipart/form-data; boundary=$bound" -query $outputData]
+ set page [::http::geturl "${urlbase}$testfilename1" -type "multipart/form-data; boundary=$bound" -query $outputData]
set ret [string trim [::http::data $page]]
::http::cleanup $page
set ret
-} {uploadtest 1 42747 -- AngeloFish.jpg}
+} {uploadtest|1|42747||AngeloFish.jpg}
set testfilename1 uploadsave.rvt