Skip to content

Commit 82776ee

Browse files
committed
update get header with len inputs mandatory
1 parent 6d637a7 commit 82776ee

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

build_test_resources/linkfuntest.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void my_app_simple_get_calloc_from_pool(ngx_link_func_ctx_t *ctx) {
6363
}
6464

6565
void my_app_simple_get_header_param(ngx_link_func_ctx_t *ctx) {
66-
u_char *req_content_type = ngx_link_func_get_header(ctx, "Host");
66+
u_char *req_content_type = ngx_link_func_get_header(ctx, "Host", sizeof("Host") - 1);
6767

6868
if (req_content_type) {
6969
ngx_link_func_log_info(ctx, req_content_type);
@@ -86,8 +86,8 @@ char* login(const char* userId, const char*pass) {
8686
void my_simple_authentication(ngx_link_func_ctx_t *ctx) {
8787

8888
ngx_link_func_log_info(ctx, "Authenticating");
89-
char *userId = (char*) ngx_link_func_get_header(ctx, "userId");
90-
char *userPass = (char*) ngx_link_func_get_header(ctx, "userPass");
89+
char *userId = (char*) ngx_link_func_get_header(ctx, "userId", sizeof("userId") - 1);
90+
char *userPass = (char*) ngx_link_func_get_header(ctx, "userPass", sizeof("userPass") - 1);
9191
char* userName;
9292

9393
if ( userId == NULL || strlen(userId) == 0) {

config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ngx_feature_incs="#include <ngx_link_func_module.h>"
2424
ngx_feature_path=
2525
ngx_feature_libs=
2626
# ngx_feature_exit_if_not_found=yes
27-
ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_30;"
27+
ngx_feature_test="int ngx_link_func_module_current_version_=ngx_link_func_module_version_31;"
2828
. auto/feature
2929

3030
if [ $ngx_found != yes ]; then

src/ngx_link_func_module.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg);
206206
void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg);
207207
void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg);
208208
char *ngx_link_func_strdup(ngx_link_func_ctx_t *ctx, const char *src);
209-
u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key);
209+
u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key, size_t keylen);
210210
int ngx_link_func_add_header_in(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen, const char *value, size_t val_len );
211211
int ngx_link_func_add_header_out(ngx_link_func_ctx_t *ctx, const char *key, size_t keylen, const char *value, size_t val_len );
212212
void* ngx_link_func_get_query_param(ngx_link_func_ctx_t *ctx, const char *key);
@@ -711,7 +711,7 @@ ngx_http_link_func_pre_configuration(ngx_conf_t *cf) {
711711
return NGX_ERROR;
712712
#endif
713713

714-
#ifndef ngx_link_func_module_version_30
714+
#ifndef ngx_link_func_module_version_31
715715
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", "the ngx_http_link_func_module.h might not be latest or not found in the c header path, \
716716
please copy latest ngx_http_link_func_module.h to your /usr/include or /usr/local/include or relavent header search path \
717717
with read and write permission.");
@@ -1670,11 +1670,12 @@ ngx_http_link_func_strdup_with_p(ngx_pool_t *pool, const char *src, size_t len)
16701670
}
16711671

16721672
u_char*
1673-
ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key) {
1673+
ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key, size_t keylen) {
16741674
ngx_http_request_t *r = (ngx_http_request_t*)ctx->__r__;
16751675
ngx_list_part_t *part = &r->headers_in.headers.part;
16761676
ngx_table_elt_t *header = part->elts;
16771677
unsigned int i;
1678+
size_t header_len;
16781679
for (i = 0; /* void */; i++) {
16791680
if (i >= part->nelts) {
16801681
if (part->next == NULL) {
@@ -1686,7 +1687,8 @@ ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key) {
16861687
i = 0;
16871688
}
16881689

1689-
if (ngx_strncasecmp( (u_char*) key, header[i].key.data , header[i].key.len) == 0 ) {
1690+
header_len = header[i].key.len;
1691+
if ( header_len == keylen && ngx_strncasecmp( (u_char*) key, header[i].key.data , header_len) == 0 ) {
16901692
u_char *ret = ngx_pcalloc(r->pool, header[i].value.len + 1);
16911693
ngx_memcpy(ret, header[i].value.data, header[i].value.len);
16921694
return ret;

src/ngx_link_func_module.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <stdlib.h>
4141
#include <stdint.h>
4242

43-
#define ngx_link_func_module_version_30 30
43+
#define ngx_link_func_module_version_31 31
4444

4545

4646
#define ngx_link_func_content_type_plaintext "text/plain"
@@ -68,7 +68,7 @@ extern void ngx_link_func_log_info(ngx_link_func_ctx_t *ctx, const char* msg);
6868
extern void ngx_link_func_log_warn(ngx_link_func_ctx_t *ctx, const char* msg);
6969
extern void ngx_link_func_log_err(ngx_link_func_ctx_t *ctx, const char* msg);
7070

71-
extern u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key);
71+
extern u_char* ngx_link_func_get_header(ngx_link_func_ctx_t *ctx, const char*key, size_t keylen);
7272
extern void* ngx_link_func_get_query_param(ngx_link_func_ctx_t *ctx, const char *key);
7373
extern void* ngx_link_func_palloc(ngx_link_func_ctx_t *ctx, size_t size);
7474
extern void* ngx_link_func_pcalloc(ngx_link_func_ctx_t *ctx, size_t size);

0 commit comments

Comments
 (0)