Merge pull request #10191 from Ansuel/cgi-io-fix

cgi-io: fix various errors
This commit is contained in:
Jo-Philipp Wich 2019-10-11 12:10:47 +02:00 committed by GitHub
commit f22bd6116a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=cgi-io PKG_NAME:=cgi-io
PKG_RELEASE:=12 PKG_RELEASE:=13
PKG_LICENSE:=GPL-2.0-or-later PKG_LICENSE:=GPL-2.0-or-later

View file

@ -37,6 +37,7 @@
#include "multipart_parser.h" #include "multipart_parser.h"
#define READ_BLOCK 4096
enum part { enum part {
PART_UNKNOWN, PART_UNKNOWN,
@ -389,7 +390,7 @@ static int
filecopy(void) filecopy(void)
{ {
int len; int len;
char buf[4096]; char buf[READ_BLOCK];
if (!st.filedata) if (!st.filedata)
{ {
@ -625,7 +626,8 @@ static int
main_upload(int argc, char *argv[]) main_upload(int argc, char *argv[])
{ {
int rem, len; int rem, len;
char buf[4096]; bool done = false;
char buf[READ_BLOCK];
multipart_parser *p; multipart_parser *p;
p = init_parser(); p = init_parser();
@ -638,17 +640,14 @@ main_upload(int argc, char *argv[])
while ((len = read(0, buf, sizeof(buf))) > 0) while ((len = read(0, buf, sizeof(buf))) > 0)
{ {
if (!done) {
rem = multipart_parser_execute(p, buf, len); rem = multipart_parser_execute(p, buf, len);
done = (rem < len);
if (rem < len) }
break;
} }
multipart_parser_free(p); multipart_parser_free(p);
/* read remaining post data */
while ((len = read(0, buf, sizeof(buf))) > 0);
return 0; return 0;
} }
@ -657,7 +656,7 @@ main_download(int argc, char **argv)
{ {
char *fields[] = { "sessionid", NULL, "path", NULL, "filename", NULL, "mimetype", NULL }; char *fields[] = { "sessionid", NULL, "path", NULL, "filename", NULL, "mimetype", NULL };
unsigned long long size = 0; unsigned long long size = 0;
char *p, buf[4096]; char *p, buf[READ_BLOCK];
ssize_t len = 0; ssize_t len = 0;
struct stat s; struct stat s;
int rfd; int rfd;
@ -677,7 +676,7 @@ main_download(int argc, char **argv)
return failure(403, 0, "Requested path is not a regular file or block device"); return failure(403, 0, "Requested path is not a regular file or block device");
for (p = fields[5]; p && *p; p++) for (p = fields[5]; p && *p; p++)
if (!isalnum(*p) && !strchr(" ()<>@,;:[]?.=%", *p)) if (!isalnum(*p) && !strchr(" ()<>@,;:[]?.=%-", *p))
return failure(400, 0, "Invalid characters in filename"); return failure(400, 0, "Invalid characters in filename");
for (p = fields[7]; p && *p; p++) for (p = fields[7]; p && *p; p++)
@ -783,7 +782,7 @@ main_backup(int argc, char **argv)
fflush(stdout); fflush(stdout);
do { do {
len = splice(fds[0], NULL, 1, NULL, 4096, SPLICE_F_MORE); len = splice(fds[0], NULL, 1, NULL, READ_BLOCK, SPLICE_F_MORE);
} while (len > 0); } while (len > 0);
waitpid(pid, &status, 0); waitpid(pid, &status, 0);