Compare commits

..

No commits in common. "e6efa331b55a39a2286cfc3b0b0b8f4f31806b53" and "661631138a14b0c1f2106595a2227543cd1a39a4" have entirely different histories.

4 changed files with 5 additions and 56 deletions

View File

@ -64,13 +64,6 @@ void * ftpprchild(struct clientparam* param) {
} }
else if (!strncasecmp((char *)buf, "PASS ", 5)){ else if (!strncasecmp((char *)buf, "PASS ", 5)){
/* The user name carries the server to log in to, and it arrives
with USER. Without it there is nothing to log in to, and what
follows would read the name and the host as if there were. */
if(!param->hostname || !param->extusername){
socksend(param, param->ctrlsock, (unsigned char *)"503 Login with USER first\r\n", 27, conf.timeouts[STRING_S]);
RETURN(805);
}
param->extpassword = (unsigned char *)strdup((char *)buf+5); param->extpassword = (unsigned char *)strdup((char *)buf+5);
inbuf = BUFSIZE; inbuf = BUFSIZE;
res = ftplogin(param, (char *)buf, &inbuf); res = ftplogin(param, (char *)buf, &inbuf);

View File

@ -265,9 +265,6 @@ static FILTER_ACTION pcre_filter_client(void *fo, struct clientparam * param, vo
return (res)? CONTINUE:PASS; return (res)? CONTINUE:PASS;
} }
/* What a rewritten buffer keeps free for its caller to append to. */
#define PCRE_HEADROOM 1024
static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){
PCRE2_SIZE *ovector; PCRE2_SIZE *ovector;
int count = 0; int count = 0;
@ -327,17 +324,12 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
else if(*replace == '$' && isnumber(*(replace+1))){ else if(*replace == '$' && isnumber(*(replace+1))){
replace ++; replace ++;
num = atoi(replace); num = atoi(replace);
/* Past the digits first, and only then decide whether
the group is one to copy: the pass which measured
this string did it in that order, and a reference it
counted as nothing must not be written out as its
own digits here. */
while(isnumber(*replace)) replace++;
if(num > (count - 1)) continue; if(num > (count - 1)) continue;
if(ovector[(num<<1)] == PCRE2_UNSET) continue; if(ovector[(num<<1)] == PCRE2_UNSET) continue;
if(ovector[(num<<1) + 1] > (PCRE2_SIZE)*length_p || ovector[(num<<1)] > ovector[(num<<1) + 1]) continue; if(ovector[(num<<1) + 1] > (PCRE2_SIZE)*length_p || ovector[(num<<1)] > ovector[(num<<1) + 1]) continue;
memcpy(target, *buf_p + ovector[(num<<1)], ovector[(num<<1) + 1] - ovector[(num<<1)]); memcpy(target, *buf_p + ovector[(num<<1)], ovector[(num<<1) + 1] - ovector[(num<<1)]);
target += (ovector[(num<<1) + 1] - ovector[(num<<1)]); target += (ovector[(num<<1) + 1] - ovector[(num<<1)]);
while(isnumber(*replace)) replace++;
} }
else { else {
*target++ = *replace++; *target++ = *replace++;
@ -346,13 +338,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
repsz = (int)(target - tmpbuf); repsz = (int)(target - tmpbuf);
memcpy(target, *buf_p + ovector[1], *length_p - ovector[1]); memcpy(target, *buf_p + ovector[1], *length_p - ovector[1]);
if((ovector[0] + replen + 1) > *bufsize_p){ if((ovector[0] + replen + 1) > *bufsize_p){
/* Room beyond what was produced: whoever asked for the newbuf = pl->mallocfunc(ovector[0] + replen + 1);
filtering usually has something of its own to add, and a
buffer sized to the last byte written leaves nowhere to
put it. The size reported is the size allocated. */
int newsize = ovector[0] + replen + 1 + PCRE_HEADROOM;
newbuf = pl->mallocfunc(newsize);
if(!newbuf){ if(!newbuf){
pl->freefunc(tmpbuf); pl->freefunc(tmpbuf);
return CONTINUE; return CONTINUE;
@ -360,7 +346,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns
memcpy(newbuf, *buf_p, ovector[0]); memcpy(newbuf, *buf_p, ovector[0]);
pl->freefunc(*buf_p); pl->freefunc(*buf_p);
*buf_p = (unsigned char *)newbuf; *buf_p = (unsigned char *)newbuf;
*bufsize_p = newsize; *bufsize_p = ovector[0] + replen + 1;
} }
memcpy(*buf_p + ovector[0], tmpbuf, replen); memcpy(*buf_p + ovector[0], tmpbuf, replen);
pl->freefunc(tmpbuf); pl->freefunc(tmpbuf);

View File

@ -132,12 +132,6 @@ char * proxy_stringtable[] = {
}; };
#define LINESIZE 32768 #define LINESIZE 32768
/* "Content-Length: " plus 20 digits plus CRLF and a NUL, rounded up */
#define CLHDRSIZE 48
/* what the headers this proxy adds of its own can come to: a Forwarded or
Via with a host name in it, a Connection, a Proxy-support and a
Proxy-Authorization carrying an encoded user and password */
#define HDRRESERVE 2048
#define BUFSIZE (LINESIZE*2) #define BUFSIZE (LINESIZE*2)
#define FTPBUFSIZE 1536 #define FTPBUFSIZE 1536
@ -157,20 +151,6 @@ static int send_st(struct clientparam *param, int idx){
return socksend(param, param->clisock, (unsigned char *)proxy_stringtable[idx], pst_len(idx), conf.timeouts[STRING_S]); return socksend(param, param->clisock, (unsigned char *)proxy_stringtable[idx], pst_len(idx), conf.timeouts[STRING_S]);
} }
/* Makes room in a buffer whose size is tracked. A filter may hand back one
holding exactly what it produced, so nothing may be added to it without
asking for the room first. Returns 1 when the room cannot be had. */
static int growbuf(unsigned char **buf, int *bufsize, int need){
unsigned char *newbuf;
if(need <= *bufsize) return 0;
need += BUFSIZE; /* for what follows too, not just this */
if(!(newbuf = realloc(*buf, need))) return 1;
*buf = newbuf;
*bufsize = need;
return 0;
}
static void freeptr(void *p){ static void freeptr(void *p){
void **pp = (void **)p; void **pp = (void **)p;
if(*pp) { free(*pp); *pp = NULL; } if(*pp) { free(*pp); *pp = NULL; }
@ -607,10 +587,6 @@ for(;;){
RETURN(0); RETURN(0);
} }
if(action != PASS) RETURN(517); if(action != PASS) RETURN(517);
/* A filter may have returned a buffer sized to exactly what it produced.
The headers this proxy adds of its own go in after it, so the room for
them is taken back before anything is written. */
if(growbuf(&buf, &bufsize, inbuf + HDRRESERVE)) RETURN(21);
param->nolongdatfilter = 0; param->nolongdatfilter = 0;
#endif #endif
@ -644,7 +620,6 @@ for(;;){
contentlength64 = param->cliinbuf; contentlength64 = param->cliinbuf;
param->nolongdatfilter = 1; param->nolongdatfilter = 1;
} }
if(growbuf(&buf, &bufsize, (int)strlen((char *)buf) + CLHDRSIZE)) RETURN(21);
sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64); sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64);
} }
@ -1122,7 +1097,6 @@ for(;;){
RETURN(0); RETURN(0);
} }
if(action != PASS) RETURN(517); if(action != PASS) RETURN(517);
if(growbuf(&buf, &bufsize, inbuf + HDRRESERVE)) RETURN(21);
param->nolongdatfilter = 0; param->nolongdatfilter = 0;
@ -1146,7 +1120,6 @@ for(;;){
} }
if(action != PASS) RETURN(517); if(action != PASS) RETURN(517);
contentlength64 = param->srvinbuf; contentlength64 = param->srvinbuf;
if(growbuf(&buf, &bufsize, (int)strlen((char *)buf) + CLHDRSIZE)) RETURN(21);
sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64); sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64);
hascontent = 1; hascontent = 1;
} }

View File

@ -159,10 +159,7 @@ void * smtppchild(struct clientparam* param) {
i = de64(buf,username,255); i = de64(buf,username,255);
if(i < 1) {RETURN(664);} if(i < 1) {RETURN(664);}
username[i] = 0; username[i] = 0;
/* The name has to carry the host to connect to, and the answer says parseconnusername((char *)username, param, 0, 587);
whether it did: without one there is nowhere to go, and what follows
reads the name as if there were. */
if(parseconnusername((char *)username, param, 0, 587)) {RETURN(669);}
socksend(param, param->clisock, (unsigned char *)"334 UGFzc3dvcmQ6\r\n", 18,conf.timeouts[STRING_S]); socksend(param, param->clisock, (unsigned char *)"334 UGFzc3dvcmQ6\r\n", 18,conf.timeouts[STRING_S]);
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]); i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
if(i < 2) {RETURN(665);} if(i < 2) {RETURN(665);}
@ -187,7 +184,7 @@ void * smtppchild(struct clientparam* param) {
} }
if(i < 3 || *username) {RETURN(668);} if(i < 3 || *username) {RETURN(668);}
username[i] = 0; username[i] = 0;
if(parseconnusername((char *)username+1, param, 0, 587)) {RETURN(670);} parseconnusername((char *)username+1, param, 0, 587);
res = (int)strlen((char *)username+1) + 2; res = (int)strlen((char *)username+1) + 2;
if(res < i){ if(res < i){
if(param->extpassword) free(param->extpassword); if(param->extpassword) free(param->extpassword);