Skip to content

Commit

Permalink
format string cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Dec 1, 2024
1 parent e2b53b7 commit a36aca2
Show file tree
Hide file tree
Showing 64 changed files with 297 additions and 294 deletions.
8 changes: 4 additions & 4 deletions src/lib/bio/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fr_trie_t *fr_bio_network_trie_alloc(TALLOC_CTX *ctx, int af, fr_ipaddr_t const
* Can't add v4 networks to a v6 socket, or vice versa.
*/
if (allow[i].af != af) {
fr_strerror_printf("Address family in entry %zd - 'allow = %pV' "
fr_strerror_printf("Address family in entry %zu - 'allow = %pV' "
"does not match 'ipaddr'", i + 1, fr_box_ipaddr(allow[i]));
fail:
talloc_free(trie);
Expand Down Expand Up @@ -239,7 +239,7 @@ fr_trie_t *fr_bio_network_trie_alloc(TALLOC_CTX *ctx, int af, fr_ipaddr_t const
* Can't add v4 networks to a v6 socket, or vice versa.
*/
if (deny[i].af != af) {
fr_strerror_printf("Address family in entry %zd - 'deny = %pV' "
fr_strerror_printf("Address family in entry %zu - 'deny = %pV' "
"does not match 'ipaddr'", i + 1, fr_box_ipaddr(deny[i]));
goto fail;
}
Expand All @@ -258,7 +258,7 @@ fr_trie_t *fr_bio_network_trie_alloc(TALLOC_CTX *ctx, int af, fr_ipaddr_t const
*/
value = fr_trie_lookup_by_key(trie, &deny[i].addr, deny[i].prefix);
if (!value) {
fr_strerror_printf("The network in entry %zd - 'deny = %pV' is not "
fr_strerror_printf("The network in entry %zu - 'deny = %pV' is not "
"contained within a previous 'allow'", i + 1, fr_box_ipaddr(deny[i]));
goto fail;
}
Expand All @@ -267,7 +267,7 @@ fr_trie_t *fr_bio_network_trie_alloc(TALLOC_CTX *ctx, int af, fr_ipaddr_t const
* A "deny" cannot be within a previous "deny".
*/
if (value == FR_BIO_NETWORK_DENY) {
fr_strerror_printf("The network in entry %zd - 'deny = %pV' is overlaps "
fr_strerror_printf("The network in entry %zu - 'deny = %pV' is overlaps "
"with another 'deny' rule", i + 1, fr_box_ipaddr(deny[i]));
goto fail;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/eap/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ static bool eap_is_valid(TALLOC_CTX *ctx, eap_packet_raw_t **eap_packet_p)
*/
packet_len = talloc_array_length((uint8_t *) eap_packet);
if (packet_len <= EAP_HEADER_LEN) {
fr_strerror_printf("Invalid EAP data length %zd <= 4", packet_len);
fr_strerror_printf("Invalid EAP data length %zu <= 4", packet_len);
return false;
}

memcpy(&len, eap_packet->length, sizeof(uint16_t));
len = ntohs(len);

if ((len <= EAP_HEADER_LEN) || (len > packet_len)) {
fr_strerror_printf("Invalid EAP length field. Expected value in range %u-%zu, was %u bytes",
fr_strerror_printf("Invalid EAP length field. Expected value in range %d-%zu, was %u bytes",
EAP_HEADER_LEN, packet_len, len);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/eap/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,14 @@ rlm_rcode_t eap_compose(eap_session_t *eap_session)

default:
/* Should never enter here */
REDEBUG("Reply code %d is unknown, rejecting the request", reply->code);
REDEBUG("Reply code %u is unknown, rejecting the request", reply->code);
request->reply->code = FR_RADIUS_CODE_ACCESS_REJECT;
reply->code = FR_EAP_CODE_FAILURE;
rcode = RLM_MODULE_REJECT;
break;
}

RDEBUG2("Sending EAP %s (code %i) ID %d length %i",
RDEBUG2("Sending EAP %s (code %d) ID %d length %i",
eap_codes[eap_packet->code], eap_packet->code, reply->id,
eap_packet->length[0] * 256 + eap_packet->length[1]);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/eap_aka_sim/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static int fr_aka_sim_find_mac(uint8_t const **out, uint8_t *data, size_t data_l
if (p[0] == FR_MAC) {
len = p[1] << 2;
if ((p + len) > end) {
fr_strerror_printf("Malformed AT_MAC: Length (%zu) exceeds buffer (%zu)", len, end - p);
fr_strerror_printf("Malformed AT_MAC: Length (%zu) exceeds buffer (%zu)", len, (size_t) (end - p));
return -1;
}

Expand Down Expand Up @@ -1243,11 +1243,11 @@ void fr_aka_sim_crypto_keys_log(request_t *request, fr_aka_sim_keys_t *keys)

for (i = 0; i < keys->gsm.num_vectors; i++) {
RHEXDUMP_INLINE3(keys->gsm.vector[i].rand, AKA_SIM_VECTOR_GSM_RAND_SIZE,
"[%i] RAND :", i);
"[%u] RAND :", i);
RHEXDUMP_INLINE3(keys->gsm.vector[i].sres, AKA_SIM_VECTOR_GSM_SRES_SIZE,
"[%i] SRES :", i);
"[%u] SRES :", i);
RHEXDUMP_INLINE3(keys->gsm.vector[i].kc, AKA_SIM_VECTOR_GSM_KC_SIZE,
"[%i] KC :", i);
"[%u] KC :", i);
}
}
break;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/eap_aka_sim/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ static ssize_t sim_decode_tlv(TALLOC_CTX *ctx, fr_pair_list_t *out,
if ((p + sim_at_len) > end) {
fr_strerror_printf("%s: Malformed nested attribute %d: Length field (%zu bytes) value "
"longer than remaining data in parent (%zu bytes)",
__FUNCTION__, sim_at, sim_at_len, end - p);
__FUNCTION__, sim_at, sim_at_len, (size_t) (end - p));

error:
talloc_free(decr);
Expand Down Expand Up @@ -597,13 +597,13 @@ static ssize_t sim_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_di
res_len /= 8;

if (res_len > (attr_len - 2)) {
fr_strerror_printf("%s: RES Length field value (%u bits) > attribute value length (%zu bits)",
fr_strerror_printf("%s: RES Length field value (%d bits) > attribute value length (%zu bits)",
__FUNCTION__, res_len * 8, (attr_len - 2) * 8);
return -1;
}

if ((res_len < 4) || (res_len > 16)) {
fr_strerror_printf("%s: RES Length field value must be between 32-128 bits, got %u bits",
fr_strerror_printf("%s: RES Length field value must be between 32-128 bits, got %d bits",
__FUNCTION__, (res_len * 8));
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/eap_aka_sim/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ ssize_t fr_aka_sim_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *en
PAIR_VERIFY(vp);

if (vp->da->depth > FR_DICT_MAX_TLV_STACK) {
fr_strerror_printf("%s: Attribute depth %i exceeds maximum nesting depth %i",
fr_strerror_printf("%s: Attribute depth %u exceeds maximum nesting depth %d",
__FUNCTION__, vp->da->depth, FR_DICT_MAX_TLV_STACK);
return PAIR_ENCODE_FATAL_ERROR;
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/eap_aka_sim/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ int fr_aka_sim_id_3gpp_pseudonym_encrypt(char out[AKA_SIM_3GPP_PSEUDONYM_LEN + 1
u_p += 3;
}
if ((out_p - out) != AKA_SIM_3GPP_PSEUDONYM_LEN) {
fr_strerror_printf("Base64 output length invalid, expected %i bytes, got %zu bytes",
AKA_SIM_3GPP_PSEUDONYM_LEN, out_p - out);
fr_strerror_printf("Base64 output length invalid, expected %u bytes, got %zu bytes",
AKA_SIM_3GPP_PSEUDONYM_LEN, (size_t) (out_p - out));
return -1;
}

Expand Down Expand Up @@ -645,7 +645,7 @@ int fr_aka_sim_id_3gpp_pseudonym_decrypt(char out[AKA_SIM_IMSI_MAX_LEN + 1],
* some sort of memory corruption has occurred.
*/
if (unlikely(decr_len > (AKA_SIM_IMSI_MAX_LEN + 1))) {
fr_strerror_printf("Decrypted data len invalid. Expected %i bytes, got %zu bytes",
fr_strerror_printf("Decrypted data len invalid. Expected %u bytes, got %zu bytes",
(AKA_SIM_IMSI_MAX_LEN + 1), decr_len);
goto error;
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/eap_aka_sim/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int vector_opc_from_op(request_t *request, uint8_t const **out, uint8_t o
opc_vp = fr_pair_find_by_da(list, NULL, attr_sim_opc);
if (opc_vp) {
if (opc_vp->vp_length != MILENAGE_OPC_SIZE) {
REDEBUG("&control.%s has incorrect length, expected %u bytes got %zu bytes",
REDEBUG("&control.%s has incorrect length, expected %d bytes got %zu bytes",
attr_sim_opc->name, MILENAGE_OPC_SIZE, opc_vp->vp_length);
return -1;
}
Expand All @@ -60,7 +60,7 @@ static int vector_opc_from_op(request_t *request, uint8_t const **out, uint8_t o
op_vp = fr_pair_find_by_da(list, NULL, attr_sim_op);
if (op_vp) {
if (op_vp->vp_length != MILENAGE_OP_SIZE) {
REDEBUG("&control.%s has incorrect length, expected %u bytes got %zu bytes",
REDEBUG("&control.%s has incorrect length, expected %d bytes got %zu bytes",
attr_sim_op->name, MILENAGE_OP_SIZE, op_vp->vp_length);
return -1;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ static int vector_gsm_from_ki(request_t *request, fr_pair_list_t *vps, int idx,
break;

default:
REDEBUG("Unknown/unsupported algorithm %i", version);
REDEBUG("Unknown/unsupported algorithm %u", version);
return -1;
}

Expand Down Expand Up @@ -432,7 +432,7 @@ static int vector_umts_from_ki(request_t *request, fr_pair_list_t *vps, fr_aka_s
return -1;

default:
REDEBUG("Unknown/unsupported algorithm %i", version);
REDEBUG("Unknown/unsupported algorithm %u", version);
return -1;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib/eap_aka_sim/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static xlat_action_t aka_sim_id_3gpp_temporary_id_key_index_xlat(TALLOC_CTX *ctx
fr_value_box_t *vb;

if (id->vb_length != AKA_SIM_3GPP_PSEUDONYM_LEN) {
REDEBUG2("3gpp pseudonym incorrect length, expected %i bytes, got %zu bytes",
REDEBUG2("3gpp pseudonym incorrect length, expected %u bytes, got %zu bytes",
AKA_SIM_3GPP_PSEUDONYM_LEN, id->vb_length);
return XLAT_ACTION_FAIL;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ static xlat_action_t aka_sim_3gpp_temporary_id_decrypt_xlat(TALLOC_CTX *ctx, fr_
if (tag_vb) include_tag = tag_vb->vb_bool;

if (id_len != (AKA_SIM_3GPP_PSEUDONYM_LEN)) {
REDEBUG2("3gpp pseudonym incorrect length, expected %i bytes, got %zu bytes",
REDEBUG2("3gpp pseudonym incorrect length, expected %u bytes, got %zu bytes",
AKA_SIM_3GPP_PSEUDONYM_LEN, id_len);
error:
return XLAT_ACTION_FAIL;
Expand Down Expand Up @@ -471,7 +471,7 @@ static xlat_action_t aka_sim_3gpp_temporary_id_encrypt_xlat(TALLOC_CTX *ctx, fr_
id_p = id;
id_end = id_p + id_len;
} else {
REDEBUG2("IMSI incorrect length, expected %i bytes, got %zu bytes", AKA_SIM_IMSI_MAX_LEN + 1,
REDEBUG2("IMSI incorrect length, expected %u bytes, got %zu bytes", AKA_SIM_IMSI_MAX_LEN + 1,
id_len);
goto error;

Expand Down
20 changes: 10 additions & 10 deletions src/lib/server/cf_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ char const *cf_expand_variables(char const *cf, int lineno,

if (buf.st_size >= ((output + outsize) - p)) {
close(fd);
ERROR("%s[%d]: Reference \"${%s}\" file is too large (%zd >= %zd)", cf, lineno, name,
(size_t) buf.st_size, ((output + outsize) - p));
ERROR("%s[%d]: Reference \"${%s}\" file is too large (%zu >= %zu)", cf, lineno, name,
(size_t) buf.st_size, (size_t) ((output + outsize) - p));
return NULL;
}

Expand Down Expand Up @@ -696,30 +696,30 @@ bool cf_file_check(CONF_PAIR *cp, bool check_perms)

if ((conf_check_gid != (gid_t)-1) && ((egid = getegid()) != conf_check_gid)) {
if (setegid(conf_check_gid) < 0) {
cf_log_perr(cp, "Failed setting effective group ID (%i) for file check: %s",
conf_check_gid, fr_syserror(errno));
cf_log_perr(cp, "Failed setting effective group ID (%d) for file check: %s",
(int) conf_check_gid, fr_syserror(errno));
goto error;
}
}
if ((conf_check_uid != (uid_t)-1) && ((euid = geteuid()) != conf_check_uid)) {
if (seteuid(conf_check_uid) < 0) {
cf_log_perr(cp, "Failed setting effective user ID (%i) for file check: %s",
conf_check_uid, fr_syserror(errno));
cf_log_perr(cp, "Failed setting effective user ID (%d) for file check: %s",
(int) conf_check_uid, fr_syserror(errno));
goto error;
}
}
fd = open(filename, O_RDONLY);
if (conf_check_uid != euid) {
if (seteuid(euid) < 0) {
cf_log_perr(cp, "Failed restoring effective user ID (%i) after file check: %s",
euid, fr_syserror(errno));
cf_log_perr(cp, "Failed restoring effective user ID (%d) after file check: %s",
(int) euid, fr_syserror(errno));
goto error;
}
}
if (conf_check_gid != egid) {
if (setegid(egid) < 0) {
cf_log_perr(cp, "Failed restoring effective group ID (%i) after file check: %s",
egid, fr_syserror(errno));
cf_log_perr(cp, "Failed restoring effective group ID (%d) after file check: %s",
(int) egid, fr_syserror(errno));
goto error;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/cf_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static int cf_pair_unescape(CONF_PAIR *cp, conf_parser_t const *rule)
p = cp->value;
q = str;
while (*p) {
int x;
unsigned int x;

if (*p != '\\') {
*(q++) = *(p++);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/cf_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ do {\
#define FR_INTEGER_COND_CHECK(_name, _var, _cond, _new)\
do {\
if (!(_cond)) {\
WARN("Ignoring \"" _name " = %i\", forcing to \"" _name " = %i\"", _var, _new);\
WARN("Ignoring \"" _name " = %u\", forcing to \"" _name " = %u\"", (unsigned int) (_var), (unsigned int) (_new));\
_var = _new;\
}\
} while (0)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/server/cf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ void _cf_item_debug(CONF_ITEM const *ci)
DEBUG(" name1 : %s", cs->name1);
DEBUG(" name2 : %s", cs->name2 ? cs->name2 : "<none>");
DEBUG(" name2_quote : %s", fr_table_str_by_value(fr_token_quotes_table, cs->name2_quote, "<INVALID>"));
DEBUG(" argc : %u", cs->argc);
DEBUG(" argc : %d", cs->argc);

for (i = 0; i < cs->argc; i++) {
char const *quote = fr_table_str_by_value(fr_token_quotes_table, cs->argv_quote[i], "<INVALID>");
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ static void _connection_error(UNUSED fr_event_list_t *el, int fd, UNUSED int fla
{
connection_t *conn = talloc_get_type_abort(uctx, connection_t);

ERROR("Connection failed for fd (%u): %s", fd, fr_syserror(fd_errno));
ERROR("Connection failed for fd (%d): %s", fd, fr_syserror(fd_errno));
connection_state_enter_failed(conn);
}

Expand Down Expand Up @@ -1415,7 +1415,7 @@ int connection_signal_on_fd(connection_t *conn, int fd)
_connection_writable,
_connection_error,
conn) < 0) {
PERROR("Failed inserting fd (%u) into event loop %p",
PERROR("Failed inserting fd (%d) into event loop %p",
fd, conn->pub.el);
connection_state_enter_failed(conn);
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/server/time_tracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ static inline void fr_time_tracking_end(fr_time_delta_t *predicted,
*/
static inline CC_HINT(nonnull) void fr_time_tracking_debug(fr_time_tracking_t *tt, FILE *fp)
{
#define DPRINT_TIME(_x) fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_unwrap(tt->_x))
#define DPRINT(_x) fprintf(fp, "\t" #_x " = %"PRIu64"\n", fr_time_delta_unwrap(tt->_x))
#define DPRINT_TIME(_x) fprintf(fp, "\t" #_x " = %"PRId64"\n", fr_time_unwrap(tt->_x))
#define DPRINT(_x) fprintf(fp, "\t" #_x " = %"PRId64"\n", fr_time_delta_unwrap(tt->_x))

DPRINT_TIME(started);
DPRINT_TIME(ended);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/tls/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void *fr_openssl_talloc(size_t len, char const *file, NDEBUG_UNUSED int l

chunk = talloc_array(ssl_talloc_ctx, uint8_t, len);
#ifndef NDEBUG
talloc_set_name(chunk, "%s:%u", file, line);
talloc_set_name(chunk, "%s:%d", file, line);
#endif
return chunk;
}
Expand All @@ -256,7 +256,7 @@ static void *fr_openssl_talloc_realloc(void *old, size_t len, NDEBUG_UNUSED char

chunk = talloc_realloc_size(ssl_talloc_ctx, old, len);
#ifndef NDEBUG
talloc_set_name(chunk, "%s:%u", file, line);
talloc_set_name(chunk, "%s:%d", file, line);
#endif
return chunk;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ SSL_CTX *fr_tls_ctx_alloc(fr_tls_conf_t const *conf, bool client)
DEBUG3("Configured ciphers (by priority)");

while ((cipher = SSL_get_cipher_list(ssl, i))) {
DEBUG3("[%i] %s", i, cipher);
DEBUG3("[%u] %s", i, cipher);
i++; /* Print index starting at zero */
}

Expand Down
11 changes: 6 additions & 5 deletions src/lib/tls/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void fr_tls_session_info_cb(SSL const *ssl, int where, int ret)
}
# endif
} else {
ROPTIONAL(RDEBUG2, DEBUG2, "Handshake state - %s%s (%i)", role, state, SSL_get_state(ssl));
ROPTIONAL(RDEBUG2, DEBUG2, "Handshake state - %s%s (%u)", role, state, SSL_get_state(ssl));
}
return;
}
Expand Down Expand Up @@ -619,7 +619,8 @@ static void session_msg_log(request_t *request, fr_tls_session_t *tls_session, u

if (((size_t)tls_session->info.version >= NUM_ELEMENTS(tls_version_str)) ||
!tls_version_str[tls_session->info.version]) {
snprintf(unknown_version, sizeof(unknown_version), "unknown_tls_version_0x%04x", tls_session->info.version);
snprintf(unknown_version, sizeof(unknown_version), "unknown_tls_version_0x%04x",
(unsigned int) tls_session->info.version);
version = unknown_version;
} else {
version = tls_version_str[tls_session->info.version];
Expand All @@ -631,7 +632,7 @@ static void session_msg_log(request_t *request, fr_tls_session_t *tls_session, u
if (((size_t)tls_session->info.content_type >= NUM_ELEMENTS(tls_content_type_str)) ||
!tls_content_type_str[tls_session->info.content_type]) {
snprintf(unknown_content_type, sizeof(unknown_content_type),
"unknown_content_type_0x%04x", tls_session->info.content_type);
"unknown_content_type_0x%04x", (unsigned int) tls_session->info.content_type);
content_type = unknown_content_type;
} else {
content_type = tls_content_type_str[tls_session->info.content_type];
Expand Down Expand Up @@ -954,7 +955,7 @@ int fr_tls_session_recv(request_t *request, fr_tls_session_t *tls_session)
ret = BIO_write(tls_session->into_ssl, tls_session->dirty_in.data, tls_session->dirty_in.used);
if (ret != (int) tls_session->dirty_in.used) {
record_init(&tls_session->dirty_in);
REDEBUG("Failed writing %zd bytes to SSL BIO: %d", tls_session->dirty_in.used, ret);
REDEBUG("Failed writing %zu bytes to SSL BIO: %d", tls_session->dirty_in.used, ret);
goto error;
}

Expand Down Expand Up @@ -1542,7 +1543,7 @@ static unlang_action_t tls_session_async_handshake(rlm_rcode_t *p_result, int *p
if (tls_session->dirty_in.used) {
ret = BIO_write(tls_session->into_ssl, tls_session->dirty_in.data, tls_session->dirty_in.used);
if (ret != (int)tls_session->dirty_in.used) {
REDEBUG("Failed writing %zd bytes to TLS BIO: %d", tls_session->dirty_in.used, ret);
REDEBUG("Failed writing %zu bytes to TLS BIO: %d", tls_session->dirty_in.used, ret);
record_init(&tls_session->dirty_in);
goto error;
}
Expand Down
Loading

0 comments on commit a36aca2

Please sign in to comment.