1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-10 11:48:53 +00:00

Handle upload boundary without CRLF (#427)

Handle boundary for form field without CRLF
This commit is contained in:
feiniks
2020-12-22 18:38:44 +08:00
committed by GitHub
parent 193ec9381e
commit f31ec3bfc4

View File

@@ -1981,6 +1981,18 @@ recv_form_field (RecvFSM *fsm, gboolean *no_line)
} }
free (line); free (line);
} else { } else {
size_t size = evbuffer_get_length (fsm->line);
if (size > 0) {
char *buf = g_new (char, size);
evbuffer_remove (fsm->line, buf, size);
if (strstr(buf, fsm->boundary) != NULL) {
seaf_debug ("[upload] form field ends.\n");
g_free (fsm->input_name);
fsm->input_name = NULL;
fsm->state = RECV_HEADERS;
}
}
*no_line = TRUE; *no_line = TRUE;
} }
@@ -2029,33 +2041,39 @@ recv_file_data (RecvFSM *fsm, gboolean *no_line)
line = evbuffer_readln (fsm->line, &len, EVBUFFER_EOL_CRLF_STRICT); line = evbuffer_readln (fsm->line, &len, EVBUFFER_EOL_CRLF_STRICT);
if (!line) { if (!line) {
/* If we haven't read an entire line, but the line // handle boundary
* buffer gets too long, flush the content to file. size_t size = evbuffer_get_length (fsm->line);
* It should be safe to assume the boundary line is if (size > 0) {
* no longer than 10240 bytes.
*/
if (evbuffer_get_length (fsm->line) >= MAX_CONTENT_LINE) {
seaf_debug ("[upload] recv file data %d bytes.\n",
evbuffer_get_length(fsm->line));
if (fsm->recved_crlf) {
if (writen (fsm->fd, "\r\n", 2) < 0) {
seaf_warning ("[upload] Failed to write temp file: %s.\n",
strerror(errno));
return EVHTP_RES_SERVERR;
}
}
size_t size = evbuffer_get_length (fsm->line);
char *buf = g_new (char, size); char *buf = g_new (char, size);
evbuffer_remove (fsm->line, buf, size); evbuffer_remove (fsm->line, buf, size);
if (writen (fsm->fd, buf, size) < 0) { if (strstr(buf, fsm->boundary) != NULL) {
seaf_warning ("[upload] Failed to write temp file: %s.\n", seaf_debug ("[upload] file data ends.\n");
strerror(errno)); evhtp_res res = add_uploaded_file (fsm);
g_free (buf); if (res != EVHTP_RES_OK) {
return EVHTP_RES_SERVERR; g_free(buf);
return res;
}
g_free (fsm->input_name);
fsm->input_name = NULL;
fsm->state = RECV_HEADERS;
} else {
seaf_debug ("[upload] recv file data %d bytes.\n", size);
if (fsm->recved_crlf) {
if (writen (fsm->fd, "\r\n", 2) < 0) {
seaf_warning ("[upload] Failed to write temp file: %s.\n",
strerror(errno));
return EVHTP_RES_SERVERR;
}
}
if (writen (fsm->fd, buf, size) < 0) {
seaf_warning ("[upload] Failed to write temp file: %s.\n",
strerror(errno));
g_free (buf);
return EVHTP_RES_SERVERR;
}
fsm->recved_crlf = FALSE;
} }
g_free (buf); g_free(buf);
fsm->recved_crlf = FALSE;
} }
*no_line = TRUE; *no_line = TRUE;
} else if (strstr (line, fsm->boundary) != NULL) { } else if (strstr (line, fsm->boundary) != NULL) {