mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MEDIUM: remove remains of BUFSIZE in HTTP auth and sample conversions
Sample conversions rely on two alternative buffers which were previously allocated as static bufs of size BUFSIZE. Now they're initialized to the global buffer size. It was the same for HTTP authentication. Note that it seems that none of them was prone to any mistake when dealing with the buffer size, but better stay on the safe side by maintaining the old assumption that a trash buffer is always "large enough".
This commit is contained in:
parent
19d14ef104
commit
7e2c647ee7
@ -53,6 +53,7 @@ extern const int http_err_codes[HTTP_ERR_SIZE];
|
|||||||
extern struct chunk http_err_chunks[HTTP_ERR_SIZE];
|
extern struct chunk http_err_chunks[HTTP_ERR_SIZE];
|
||||||
extern const char *HTTP_302;
|
extern const char *HTTP_302;
|
||||||
extern const char *HTTP_303;
|
extern const char *HTTP_303;
|
||||||
|
extern char *get_http_auth_buff;
|
||||||
|
|
||||||
#define HTTP_IS_CTL(x) (http_is_ctl[(unsigned char)(x)])
|
#define HTTP_IS_CTL(x) (http_is_ctl[(unsigned char)(x)])
|
||||||
#define HTTP_IS_SEP(x) (http_is_sep[(unsigned char)(x)])
|
#define HTTP_IS_SEP(x) (http_is_sep[(unsigned char)(x)])
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
#include <types/sample.h>
|
#include <types/sample.h>
|
||||||
#include <types/stick_table.h>
|
#include <types/stick_table.h>
|
||||||
|
|
||||||
|
/* only exported for late memory allocation, do not use */
|
||||||
|
extern char *sample_trash_buf1;
|
||||||
|
extern char *sample_trash_buf2;
|
||||||
|
|
||||||
struct sample_expr *sample_parse_expr(char **str, int *idx, char *err, int err_size);
|
struct sample_expr *sample_parse_expr(char **str, int *idx, char *err, int err_size);
|
||||||
struct sample *sample_process(struct proxy *px, struct session *l4,
|
struct sample *sample_process(struct proxy *px, struct session *l4,
|
||||||
void *l7, unsigned int dir, struct sample_expr *expr,
|
void *l7, unsigned int dir, struct sample_expr *expr,
|
||||||
|
@ -742,6 +742,10 @@ void init(int argc, char **argv)
|
|||||||
global.nbproc = 1;
|
global.nbproc = 1;
|
||||||
|
|
||||||
swap_buffer = (char *)calloc(1, global.tune.bufsize);
|
swap_buffer = (char *)calloc(1, global.tune.bufsize);
|
||||||
|
sample_trash_buf1 = (char *)calloc(1, global.tune.bufsize);
|
||||||
|
sample_trash_buf2 = (char *)calloc(1, global.tune.bufsize);
|
||||||
|
get_http_auth_buff = (char *)calloc(1, global.tune.bufsize);
|
||||||
|
|
||||||
|
|
||||||
fdinfo = (struct fdinfo *)calloc(1,
|
fdinfo = (struct fdinfo *)calloc(1,
|
||||||
sizeof(struct fdinfo) * (global.maxsock));
|
sizeof(struct fdinfo) * (global.maxsock));
|
||||||
|
@ -1196,7 +1196,7 @@ const char *http_parse_reqline(struct http_msg *msg,
|
|||||||
* searching again for something we are unable to find anyway.
|
* searching again for something we are unable to find anyway.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char get_http_auth_buff[BUFSIZE];
|
char *get_http_auth_buff;
|
||||||
|
|
||||||
int
|
int
|
||||||
get_http_auth(struct session *s)
|
get_http_auth(struct session *s)
|
||||||
@ -1245,7 +1245,7 @@ get_http_auth(struct session *s)
|
|||||||
if (!strncasecmp("Basic", auth_method.str, auth_method.len)) {
|
if (!strncasecmp("Basic", auth_method.str, auth_method.len)) {
|
||||||
|
|
||||||
len = base64dec(txn->auth.method_data.str, txn->auth.method_data.len,
|
len = base64dec(txn->auth.method_data.str, txn->auth.method_data.len,
|
||||||
get_http_auth_buff, BUFSIZE - 1);
|
get_http_auth_buff, global.tune.bufsize - 1);
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
20
src/sample.c
20
src/sample.c
@ -15,6 +15,8 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <common/chunk.h>
|
#include <common/chunk.h>
|
||||||
#include <common/standard.h>
|
#include <common/standard.h>
|
||||||
|
|
||||||
@ -28,11 +30,8 @@ static struct sample temp_smp;
|
|||||||
static struct chunk trash_chunk;
|
static struct chunk trash_chunk;
|
||||||
|
|
||||||
/* trash buffers used or sample conversions */
|
/* trash buffers used or sample conversions */
|
||||||
static char sample_trash_buf1[BUFSIZE];
|
char *sample_trash_buf1;
|
||||||
static char sample_trash_buf2[BUFSIZE];
|
char *sample_trash_buf2;
|
||||||
|
|
||||||
/* sample_trash_buf point on used buffer*/
|
|
||||||
static char *sample_trash_buf = sample_trash_buf1;
|
|
||||||
|
|
||||||
/* list head of all known sample fetch keywords */
|
/* list head of all known sample fetch keywords */
|
||||||
static struct sample_fetch_kw_list sample_fetches = {
|
static struct sample_fetch_kw_list sample_fetches = {
|
||||||
@ -109,12 +108,13 @@ struct sample_conv *find_sample_conv(const char *kw, int len)
|
|||||||
*/
|
*/
|
||||||
struct chunk *sample_get_trash_chunk(void)
|
struct chunk *sample_get_trash_chunk(void)
|
||||||
{
|
{
|
||||||
if (sample_trash_buf == sample_trash_buf1)
|
char *sample_trash_buf;
|
||||||
sample_trash_buf = sample_trash_buf2;
|
|
||||||
else
|
|
||||||
sample_trash_buf = sample_trash_buf1;
|
|
||||||
|
|
||||||
chunk_init(&trash_chunk, sample_trash_buf, BUFSIZE);
|
sample_trash_buf = sample_trash_buf1;
|
||||||
|
sample_trash_buf1 = sample_trash_buf2;
|
||||||
|
sample_trash_buf2 = sample_trash_buf1;
|
||||||
|
|
||||||
|
chunk_init(&trash_chunk, sample_trash_buf, global.tune.bufsize);
|
||||||
|
|
||||||
return &trash_chunk;
|
return &trash_chunk;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user