Skip to content

Commit 5521109

Browse files
committed
code: loop over authz arrays with index instead of pointer
Signed-off-by: Hans Zandbelt <[email protected]>
1 parent b9c1df2 commit 5521109

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
12/11/2024
2+
- code: loop over authz arrays with index instead of pointer
3+
14
12/10/2024
25
- github: add SonarQube analysis to Github workflows
36
- code: use snprintf instead of sprintf

src/handle/authz.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ static apr_byte_t oidc_authz_match_pcre_array(request_rec *r, const char *spec,
196196
struct oidc_pcre *);
197197

198198
// clang-format off
199+
#define OIDC_AUTHZ_PCRE_HANDLERS_NUMBER 2
200+
199201
static oidc_authz_pcre_handler_t _oidc_authz_pcre_handlers[] = {
200202
{ JSON_ARRAY, oidc_authz_match_pcre_array },
201-
{ JSON_STRING, oidc_authz_match_pcre_string },
202-
{ 0, NULL}
203+
{ JSON_STRING, oidc_authz_match_pcre_string }
203204
};
204205
// clang-format on
205206

@@ -237,7 +238,7 @@ static apr_byte_t oidc_authz_match_pcre(request_rec *r, const char *spec, json_t
237238
apr_byte_t rc = FALSE;
238239
struct oidc_pcre *preg = NULL;
239240
char *s_err = NULL;
240-
oidc_authz_pcre_handler_t *h = NULL;
241+
int i = 0;
241242

242243
if ((spec == NULL) || (val == NULL) || (key == NULL))
243244
return FALSE;
@@ -249,17 +250,17 @@ static apr_byte_t oidc_authz_match_pcre(request_rec *r, const char *spec, json_t
249250
}
250251

251252
// loop over the JSON object PCRE handlers
252-
for (h = _oidc_authz_pcre_handlers; h->handler; h++) {
253-
if (h->type == json_typeof(val)) {
253+
for (i = 0; i < OIDC_AUTHZ_PCRE_HANDLERS_NUMBER; i++) {
254+
if (_oidc_authz_pcre_handlers[i].type == json_typeof(val)) {
254255
// break out of the loop because we found a handler, and possibly a match
255-
if (h->handler(r, spec, val, key, preg) == TRUE)
256+
if (_oidc_authz_pcre_handlers[i].handler(r, spec, val, key, preg) == TRUE)
256257
rc = TRUE;
257258
break;
258259
}
259260
}
260261

261262
// see if we have found an object handler
262-
if (h->handler == NULL)
263+
if (i == OIDC_AUTHZ_PCRE_HANDLERS_NUMBER)
263264
oidc_warn(r, "unhandled JSON object type [%d] for key \"%s\"", json_typeof(val), key);
264265

265266
oidc_pcre_free(preg);
@@ -282,25 +283,27 @@ static apr_byte_t oidc_authz_separator_dot(request_rec *r, const char *spec, jso
282283
}
283284

284285
// clang-format off
286+
287+
#define OIDC_AUTHZ_SEPARATOR_HANDLERS_NUMBER 3
288+
285289
static oidc_authz_json_handler_t _oidc_authz_separator_handlers[] = {
286290
// there's some overloading going on here, applying a char as an int index
287291
{ OIDC_CHAR_COLON, oidc_authz_match_value },
288292
{ OIDC_CHAR_TILDE, oidc_authz_match_pcre },
289-
{ OIDC_CHAR_DOT, oidc_authz_separator_dot },
290-
{ 0, NULL}
293+
{ OIDC_CHAR_DOT, oidc_authz_separator_dot }
291294
};
292295
// clang-format on
293296

294297
static apr_byte_t oidc_auth_handle_separator(request_rec *r, const char *key, json_t *val, const char *spec) {
295-
oidc_authz_json_handler_t *h = NULL;
298+
int i = 0;
296299
if ((spec == NULL) || (val == NULL) || (key == NULL))
297300
return FALSE;
298-
for (h = _oidc_authz_separator_handlers; h->handler; h++) {
301+
for (i = 0; i < OIDC_AUTHZ_SEPARATOR_HANDLERS_NUMBER; i++) {
299302
// there's some overloading going on here, applying a char as an int index
300-
if (h->type == (*spec)) {
303+
if (_oidc_authz_separator_handlers[i].type == (*spec)) {
301304
// skip the separator
302305
spec++;
303-
if (h->handler(r, spec, val, key) == TRUE)
306+
if (_oidc_authz_separator_handlers[i].handler(r, spec, val, key) == TRUE)
304307
return TRUE;
305308
}
306309
}

0 commit comments

Comments
 (0)