Skip to content

Commit 07f6f99

Browse files
replace sizeof with strlen (#116)
1 parent 2062be5 commit 07f6f99

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

.github/workflows/ci.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ on:
1515

1616
jobs:
1717
build:
18+
name: "NGINX: ${{ matrix.nginx-version }}; libjwt: ${{ matrix.libjwt-version }}"
1819
strategy:
1920
matrix:
2021
# Each nginx version to build against
21-
nginx-version: ['1.20.2', '1.22.1', '1.24.0', '1.25.1']
22+
nginx-version: ['1.20.2', '1.22.1', '1.24.0', '1.25.3']
2223
# The following versions of libjwt are compatible:
2324
# * v1.0 - v1.12.0
2425
# * v1.12.1 - v1.14.0
@@ -90,14 +91,14 @@ jobs:
9091
- name: Create release archive
9192
run: |
9293
cp ./nginx/objs/ngx_http_auth_jwt_module.so ./
93-
tar czf ngx_http_auth_jwt_module_${{github.ref_name}}_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz ngx_http_auth_jwt_module.so
94+
tar czf ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz ngx_http_auth_jwt_module.so
9495
9596
- name: Upload build artifact
9697
uses: actions/upload-artifact@v3
9798
with:
9899
if-no-files-found: error
99-
name: ngx_http_auth_jwt_module_${{github.ref_name}}_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
100-
path: ngx_http_auth_jwt_module_${{github.ref_name}}_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
100+
name: ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
101+
path: ngx_http_auth_jwt_module_libjwt_${{matrix.libjwt-version}}_nginx_${{matrix.nginx-version}}.tgz
101102

102103
update_releases_page:
103104
name: Upload builds to Releases

src/ngx_http_auth_jwt_module.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static ngx_int_t redirect(ngx_http_request_t *r, auth_jwt_conf_t *jwtcf)
489489
}
490490

491491
r->headers_out.location->hash = 1;
492-
r->headers_out.location->key.len = sizeof("Location") - 1;
492+
r->headers_out.location->key.len = strlen("Location");
493493
r->headers_out.location->key.data = (u_char *)"Location";
494494

495495
if (r->method == NGX_HTTP_GET)
@@ -526,21 +526,21 @@ static ngx_int_t redirect(ngx_http_request_t *r, auth_jwt_conf_t *jwtcf)
526526
uri_escaped.len = escaped_len;
527527
ngx_escape_uri(uri_escaped.data, uri.data, uri.len, NGX_ESCAPE_ARGS);
528528

529-
r->headers_out.location->value.len = loginlen + sizeof("?return_url=") - 1 + strlen(scheme) + sizeof("://") - 1 + server.len + uri_escaped.len;
529+
r->headers_out.location->value.len = loginlen + strlen("?return_url=") + strlen(scheme) + strlen("://") + server.len + uri_escaped.len;
530530

531531
return_url = ngx_palloc(r->pool, r->headers_out.location->value.len);
532532
ngx_memcpy(return_url, jwtcf->loginurl.data, jwtcf->loginurl.len);
533533

534534
return_url_idx = jwtcf->loginurl.len;
535-
ngx_memcpy(return_url + return_url_idx, "?return_url=", sizeof("?return_url=") - 1);
535+
ngx_memcpy(return_url + return_url_idx, "?return_url=", strlen("?return_url="));
536536

537-
return_url_idx += sizeof("?return_url=") - 1;
537+
return_url_idx += strlen("?return_url=");
538538
ngx_memcpy(return_url + return_url_idx, scheme, strlen(scheme));
539539

540540
return_url_idx += strlen(scheme);
541-
ngx_memcpy(return_url + return_url_idx, "://", sizeof("://") - 1);
541+
ngx_memcpy(return_url + return_url_idx, "://", strlen("://"));
542542

543-
return_url_idx += sizeof("://") - 1;
543+
return_url_idx += strlen("://");
544544
ngx_memcpy(return_url + return_url_idx, server.data, server.len);
545545

546546
return_url_idx += server.len;
@@ -617,25 +617,25 @@ static char *get_jwt(ngx_http_request_t *r, ngx_str_t jwt_location)
617617

618618
ngx_log_debug(NGX_LOG_DEBUG, r->connection->log, 0, "jwt_location.len %d", jwt_location.len);
619619

620-
if (jwt_location.len > sizeof(HEADER_PREFIX) && ngx_strncmp(jwt_location.data, HEADER_PREFIX, sizeof(HEADER_PREFIX) - 1) == 0)
620+
if (jwt_location.len > strlen(HEADER_PREFIX) && ngx_strncmp(jwt_location.data, HEADER_PREFIX, strlen(HEADER_PREFIX)) == 0)
621621
{
622622
ngx_table_elt_t *jwtHeaderVal;
623623

624-
jwt_location.data += sizeof(HEADER_PREFIX) - 1;
625-
jwt_location.len -= sizeof(HEADER_PREFIX) - 1;
624+
jwt_location.data += strlen(HEADER_PREFIX);
625+
jwt_location.len -= strlen(HEADER_PREFIX);
626626

627627
jwtHeaderVal = search_headers_in(r, jwt_location.data, jwt_location.len);
628628

629629
if (jwtHeaderVal != NULL)
630630
{
631631
static const char *BEARER_PREFIX = "Bearer ";
632632

633-
if (ngx_strncmp(jwtHeaderVal->value.data, BEARER_PREFIX, sizeof(BEARER_PREFIX) - 1) == 0)
633+
if (ngx_strncmp(jwtHeaderVal->value.data, BEARER_PREFIX, strlen(BEARER_PREFIX)) == 0)
634634
{
635635
ngx_str_t jwtHeaderValWithoutBearer = jwtHeaderVal->value;
636636

637-
jwtHeaderValWithoutBearer.data += sizeof(BEARER_PREFIX) - 1;
638-
jwtHeaderValWithoutBearer.len -= sizeof(BEARER_PREFIX) - 1;
637+
jwtHeaderValWithoutBearer.data += strlen(BEARER_PREFIX);
638+
jwtHeaderValWithoutBearer.len -= strlen(BEARER_PREFIX);
639639

640640
jwtPtr = ngx_str_t_to_char_ptr(r->pool, jwtHeaderValWithoutBearer);
641641
}
@@ -645,13 +645,13 @@ static char *get_jwt(ngx_http_request_t *r, ngx_str_t jwt_location)
645645
}
646646
}
647647
}
648-
else if (jwt_location.len > sizeof(COOKIE_PREFIX) && ngx_strncmp(jwt_location.data, COOKIE_PREFIX, sizeof(COOKIE_PREFIX) - 1) == 0)
648+
else if (jwt_location.len > strlen(COOKIE_PREFIX) && ngx_strncmp(jwt_location.data, COOKIE_PREFIX, strlen(COOKIE_PREFIX)) == 0)
649649
{
650650
bool has_cookie = false;
651651
ngx_str_t jwtCookieVal;
652652

653-
jwt_location.data += sizeof(COOKIE_PREFIX) - 1;
654-
jwt_location.len -= sizeof(COOKIE_PREFIX) - 1;
653+
jwt_location.data += strlen(COOKIE_PREFIX);
654+
jwt_location.len -= strlen(COOKIE_PREFIX);
655655

656656
#ifndef NGX_LINKED_LIST_COOKIES
657657
if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &jwt_location, &jwtCookieVal) != NGX_DECLINED)

0 commit comments

Comments
 (0)