aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenox <as@tenoware.com>2016-08-24 01:39:13 -0700
committertenox <as@tenoware.com>2016-08-24 01:39:13 -0700
commit33915f44e7ed939748ce8fe23c7e727b58d74542 (patch)
treed09a6ac8d0ab5c66eefafcee28413ff8d7340c9a
parent6198d44fc66aef12a9e5226660cf3f2263225d13 (diff)
downloadwfm-33915f44e7ed939748ce8fe23c7e727b58d74542.tar.gz
fix upload of large files1.0.5
-rw-r--r--dialogs.c8
-rw-r--r--dir.c4
-rw-r--r--fileio.c61
-rw-r--r--wfm.c34
-rw-r--r--wfm.h2
5 files changed, 49 insertions, 60 deletions
diff --git a/dialogs.c b/dialogs.c
index 1adfd23..c17549f 100644
--- a/dialogs.c
+++ b/dialogs.c
@@ -10,7 +10,7 @@ void multiprompt_ui(char *m_action) {
int res;
char **responses;
struct stat fileinfo;
- char M_action[64];
+ char M_action[64]={0};
res=cgiFormStringMultiple("multiselect_filename", &responses);
@@ -46,7 +46,7 @@ void multiprompt_ui(char *m_action) {
checkfilename(NULL);
if(stat(phys_filename, &fileinfo)==0) {
fprintf(cgiOut, "<INPUT TYPE=\"HIDDEN\" NAME=\"filename\" VALUE=\"%s\">\n", virt_filename);
- fprintf(cgiOut, "<LI TYPE=\"square\"><B>%s/</B>", virt_filename);
+ fprintf(cgiOut, "<LI TYPE=\"square\"><B>%s</B>", virt_filename);
if(S_ISDIR(fileinfo.st_mode))
fprintf(cgiOut, " [directory %s]\n", buprintf(du(phys_filename), FALSE));
else
@@ -99,7 +99,7 @@ void multiprompt_ui(char *m_action) {
// Used for rename, mkfile, mkdir
//
void singleprompt_ui(char *m_action) {
- char M_action[64];
+ char M_action[64]={0};
snprintf(M_action, sizeof(M_action), "%c%s", toupper(m_action[0]), m_action+1);
@@ -337,7 +337,7 @@ void login_ui(void) {
void edit_ui(void) {
FILE *input;
char *buff;
- char backup[4];
+ char backup[4]={0};
char *bkcolor;
int size;
diff --git a/dir.c b/dir.c
index c22b4db..2573949 100644
--- a/dir.c
+++ b/dir.c
@@ -58,11 +58,11 @@ void dir_icoinita(void) {
void dirlist(void) {
ASDIR *direntry;
off_t size, totalsize=0;
- char highlight[VIRT_FILENAME_SIZE];
+ char highlight[VIRT_FILENAME_SIZE]={0};
char namepfx[1024], sizepfx[1024], datepfx[1024];
char rtime[64], mtime[64], atime[64];
char *stime;
- char sortby[64];
+ char sortby[64]={0};
char *name, *icon, *linecolor;
int nentr=0, e=0, n=1;
int editable;
diff --git a/fileio.c b/fileio.c
index c9b7069..2b6d65d 100644
--- a/fileio.c
+++ b/fileio.c
@@ -7,9 +7,9 @@
// Called by cgiMain action=sendfile
//
void sendfile(void) {
- char buff[1024];
+ char buff[1024]={0};
FILE *in;
- int rd, tot, size, pos, blk;
+ int rd=0, tot=0, size=0, pos=0, blk=0;
checkfilename(NULL);
@@ -36,8 +36,8 @@ void sendfile(void) {
rd=fread(buff, blk, 1, in);
if(rd) {
- tot=tot+rd*blk;
-// printf("rw=%u size=%u total=%u remaining=%u\n", rd*blk, size, tot, size-pos-(rd*blk));
+ tot+=rd*blk;
+ //fprintf(cgiOut, "rw=%u size=%u total=%u remaining=%u\n", rd*blk, size, tot, size-pos-(rd*blk));
fwrite(buff, blk, 1, cgiOut);
goto reread;
}
@@ -59,39 +59,28 @@ void sendfile(void) {
void receivefile(void) {
cgiFilePtr input;
FILE *output;
- char *buff;
- int size=0, got=0;
+ char buff[1024]={0};
+ int got=0; //,size=0;
+
+ checkfilename(NULL);
- if(cgiFormFileSize("filename", &size) != cgiFormSuccess)
- error("No file size specified.");
+ //if(cgiFormFileSize("filename", &size) != cgiFormSuccess)
+ // error("No file size specified.");
if(cgiFormFileOpen("filename", &input) != cgiFormSuccess)
error("Unable to access uploaded file.");
- buff=(char *) malloc(size+1);
- if(buff==NULL)
- error("Unable to allocate memory.");
-
- // TODO: holly crap this needs to be in a loop with a fixed buffer size similar to sendfile()
- if(cgiFormFileRead(input, buff, size, &got) != cgiFormSuccess)
- error("Reading file.");
-
- cgiFormFileClose(input);
-
- if(got != size)
- error("Wrong file size. Size=%d Received=%d.", size, got);
-
- checkfilename(NULL);
-
output=fopen(phys_filename, "wb");
if(!output)
error("Unable to open file %s for writing.<BR>%s", virt_filename, strerror(errno));
- if(fwrite(buff, size, 1, output) != 1)
- error("While writing file.<BR>%s", strerror(errno));
+ while(cgiFormFileRead(input, buff, sizeof(buff), &got) == cgiFormSuccess)
+ if(got)
+ if(fwrite(buff, got, 1, output) != 1)
+ error("While writing file.<BR>%s", strerror(errno));
+ cgiFormFileClose(input);
fclose(output);
- free(buff);
redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename, virt_dirname, token);
@@ -140,11 +129,11 @@ void edit_save(void) {
int size=0;
int tmpfd;
char *buff;
- char tempname[64];
+ char tempname[64]={0};
//FILE *output;
FILE *tempf;
- char backup[4];
- char backup_filename[PHYS_DESTINATION_SIZE];
+ char backup[4]={0};
+ char backup_filename[PHYS_DESTINATION_SIZE]={0};
regex_t re;
regmatch_t pmatch;
struct stat tmpstat;
@@ -223,7 +212,7 @@ void fileio_re_rmdir(char *dirname) {
DIR *dir;
struct dirent *direntry;
struct stat fileinfo;
- char tempfullpath[PHYS_FILENAME_SIZE];
+ char tempfullpath[PHYS_FILENAME_SIZE]={0};
dir=opendir(dirname);
if(!dir)
@@ -305,7 +294,7 @@ void delete(void) {
// Called by move()
//
void fileio_move(void) {
- char final_destination[PHYS_DESTINATION_SIZE];
+ char final_destination[PHYS_DESTINATION_SIZE]={0};
struct stat fileinfo;
// If moving file to a different directory we need to append the original file name
@@ -354,7 +343,7 @@ off_t du(char *pdir) {
DIR *dir;
struct dirent *direntry;
struct stat fileinfo;
- char child[PHYS_DIRNAME_SIZE];
+ char child[PHYS_DIRNAME_SIZE]={0};
off_t tot=0;
if(lstat(pdir, &fileinfo)==0)
@@ -387,9 +376,9 @@ off_t du(char *pdir) {
void re_dir_ui(char *vdir, int level) {
struct dirent **direntry;
struct stat fileinfo;
- char child[VIRT_DIRNAME_SIZE];
- char phy_child[PHYS_DIRNAME_SIZE];
- char re_phys_dirname[PHYS_DIRNAME_SIZE];
+ char child[VIRT_DIRNAME_SIZE]={0};
+ char phy_child[PHYS_DIRNAME_SIZE]={0};
+ char re_phys_dirname[PHYS_DIRNAME_SIZE]={0};
int n;
int nentr, e;
@@ -465,7 +454,7 @@ int asscandir(const char *dir, ASDIR **namelist, int (*compar)(const void *, con
ASDIR *names;
struct dirent *entry;
struct stat fileinfo;
- char filename[PATH_MAX];
+ char filename[PATH_MAX]={0};
int entries=0;
dirh=opendir(dir);
diff --git a/wfm.c b/wfm.c
index 14a40e8..c56bf99 100644
--- a/wfm.c
+++ b/wfm.c
@@ -18,7 +18,7 @@ void html_title(char *msg) {
// Called on early action=icon
//
int icon(void) {
- char icon_name[32];
+ char icon_name[32]={0};
cgiFormStringNoNewlines("name", icon_name, sizeof(icon_name));
@@ -70,7 +70,7 @@ void upload_status(void) {
//
char *mktoken(char *str) {
md5_state_t state;
- md5_byte_t digest[16];
+ md5_byte_t digest[16]={0};
char *outstr;
int i;
@@ -92,9 +92,9 @@ char *mktoken(char *str) {
// Called from WFM main procedure if no sufficient access permission available
//
void login(void) {
- char username[64];
- char password[64];
- char token_inp[256];
+ char username[64]={0};
+ char password[64]={0};
+ char token_inp[256]={0};
cgiFormStringNoNewlines("username", username, sizeof(username)); // only used if JavaScript not
cgiFormStringNoNewlines("password", password, sizeof(password)); // available in the browser
@@ -113,11 +113,11 @@ void login(void) {
// Called by cfg read routine during initialization
//
void access_check(char *access_string) {
- char ipaddr[32];
- char user[32];
- char pass[32];
- char type[4];
- char token_inp[64];
+ char ipaddr[32]={0};
+ char user[32]={0};
+ char pass[32]={0};
+ char type[4]={0};
+ char token_inp[64]={0};
memset(ipaddr, 0, sizeof(ipaddr));
memset(user, 0, sizeof(user));
@@ -166,7 +166,7 @@ void access_check(char *access_string) {
// Should be called by every function that uses filename
//
void checkfilename(char *inp_filename) {
- char temp_dirname[PHYS_FILENAME_SIZE];
+ char temp_dirname[PHYS_FILENAME_SIZE]={0};
char *bname;
if(inp_filename && strlen(inp_filename)) {
@@ -230,7 +230,7 @@ void checkdestination(void) {
// Only used by cgiMain during initialization
//
void checkdirectory(void) {
- char temp[VIRT_DIRNAME_SIZE];
+ char temp[VIRT_DIRNAME_SIZE]={0};
cgiFormStringNoNewlines("directory", virt_dirname, VIRT_DIRNAME_SIZE);
strip(virt_dirname, VIRT_DIRNAME_SIZE, VALIDCHRS_DST);
@@ -347,7 +347,7 @@ char *buprintf(float v, int bold) {
//
void redirect(char *location, ...) {
va_list ap;
- char buff[1024];
+ char buff[1024]={0};
va_start(ap, location);
vsnprintf(buff, sizeof(buff), location, ap);
@@ -360,11 +360,11 @@ void redirect(char *location, ...) {
// CGI entry
//
int cgiMain(void) {
- char action[32];
- char ea[8];
+ char action[32]={0};
+ char ea[8]={0};
FILE *cfgfile;
- char cfgname[128];
- char cfgline[256];
+ char cfgname[128]={0};
+ char cfgline[256]={0};
char c_tagline[]="tagline=";
char c_favicon[]="favicon=";
char c_homeurl[]="browser-url=";
diff --git a/wfm.h b/wfm.h
index 53aedd4..fec3add 100644
--- a/wfm.h
+++ b/wfm.h
@@ -1,4 +1,4 @@
-#define VERSION "1.0.4"
+#define VERSION "1.0.5"
#define copyright "<!-- WFM Version " VERSION ", Mountain View, CA, " __DATE__ " [" __TIME__ "] -->\n<!-- Copyright (c) 1994-2016 by Antoni Sawicki -->\n"
#define CSS_STYLE \