From: Arran Cudbard-Bell Date: Wed, 30 May 2018 15:17:24 +0000 (+0600) Subject: Fix more instances of manual escaping X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39bddcd70501bffd64d64f5bdcbebaeb84fd2af5;p=thirdparty%2Ffreeradius-server.git Fix more instances of manual escaping --- diff --git a/src/lib/ldap/map.c b/src/lib/ldap/map.c index 154d8f3e729..619f1520186 100644 --- a/src/lib/ldap/map.c +++ b/src/lib/ldap/map.c @@ -116,12 +116,11 @@ int fr_ldap_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp vp = fr_pair_afrom_da(ctx, map->lhs->tmpl_da); rad_assert(vp); - if (fr_pair_value_from_str(vp, self->values[i]->bv_val, self->values[i]->bv_len) < 0) { - char *escaped; - - escaped = fr_asprint(vp, self->values[i]->bv_val, self->values[i]->bv_len, '"'); - RWDEBUG("Failed parsing value \"%s\" for attribute %s: %s", escaped, - map->lhs->tmpl_da->name, fr_strerror()); + if (fr_pair_value_from_str(vp, self->values[i]->bv_val, + self->values[i]->bv_len, '\0', true) < 0) { + RPWDEBUG("Failed parsing value \"%pV\" for attribute %s: %s", + fr_box_strvalue_len(self->values[i]->bv_val, self->values[i]->bv_len), + map->lhs->tmpl_da->name); talloc_free(vp); /* also frees escaped */ continue; diff --git a/src/lib/ldap/sasl_s.c b/src/lib/ldap/sasl_s.c index d2f0722cbff..834e79a4415 100644 --- a/src/lib/ldap/sasl_s.c +++ b/src/lib/ldap/sasl_s.c @@ -182,12 +182,8 @@ fr_ldap_rcode_t fr_ldap_sasl_interactive(REQUEST *request, struct berval *srv_cred; if (ldap_parse_sasl_bind_result(conn->handle, result, &srv_cred, 0) == 0) { - char *escaped; - - escaped = fr_asprint(request, srv_cred->bv_val, srv_cred->bv_len, '\0'); - ROPTIONAL(RDEBUG3, DEBUG3, "SASL response : %s", escaped); - - talloc_free(escaped); + ROPTIONAL(RDEBUG3, DEBUG3, "SASL response : %pV", + fr_box_strvalue_len(srv_cred->bv_val, srv_cred->bv_len)); ldap_memfree(srv_cred); } } diff --git a/src/lib/redis/cluster.c b/src/lib/redis/cluster.c index 3e49842df0d..a7be9cf8009 100644 --- a/src/lib/redis/cluster.c +++ b/src/lib/redis/cluster.c @@ -1583,13 +1583,8 @@ static cluster_key_slot_t *cluster_slot_by_key(fr_redis_cluster_t *cluster, REQU */ if (rbtree_num_elements(cluster->used_nodes) > 1) { key_slot = &cluster->key_slot[cluster_key_hash(key, key_len)]; - if (RDEBUG_ENABLED2) { - char *p; - - p = fr_asprint(request, (char const *)key, key_len, '"'); - RDEBUG2("Key \"%s\" -> slot %zu", p, key_slot - cluster->key_slot); - talloc_free(p); - } + RDEBUG2("Key \"%pV\" -> slot %zu", + fr_box_strvalue_len((char const *)key, key_len), key_slot - cluster->key_slot); return key_slot; } diff --git a/src/lib/redis/redis.c b/src/lib/redis/redis.c index 8a5e8fadd6c..09b9db25dba 100644 --- a/src/lib/redis/redis.c +++ b/src/lib/redis/redis.c @@ -286,14 +286,7 @@ int fr_redis_reply_to_map(TALLOC_CTX *ctx, vp_map_t **out, REQUEST *request, RDEBUG3("Got key : %s", key->str); RDEBUG3("Got op : %s", op->str); - - if (RDEBUG_ENABLED3) { - char *p; - - p = fr_asprint(NULL, value->str, value->len, '"'); - RDEBUG3("Got value : %s", p); - talloc_free(p); - } + RDEBUG3("Got value : %pV", fr_box_strvalue_len(value->str, value->len)); map = talloc_zero(ctx, vp_map_t); slen = tmpl_afrom_attr_str(map, &map->lhs, key->str, REQUEST_CURRENT, PAIR_LIST_REQUEST, false, false); diff --git a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c index fd613319fd1..cb48c563fb5 100644 --- a/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c +++ b/src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c @@ -144,22 +144,12 @@ static cache_status_t cache_entry_find(rlm_cache_entry_t **out, * Grab all the data for this hash, should return an array * of alternating keys/values which we then convert into maps. */ - if (RDEBUG_ENABLED3) { - char *p; - - p = fr_asprint(NULL, (char const *)key, key_len, '"'); - RDEBUG3("LRANGE %s 0 -1", key); - talloc_free(p); - } + RDEBUG3("LRANGE %pV 0 -1", fr_box_strvalue_len((char const *)key, key_len)); reply = redisCommand(conn->handle, "LRANGE %b 0 -1", key, key_len); status = fr_redis_command_status(conn, reply); } if (s_ret != REDIS_RCODE_SUCCESS) { - char *p; - - p = fr_asprint(NULL, (char const *)key, key_len, '"'); - RERROR("Failed retrieving entry for key \"%s\"", p); - talloc_free(p); + RERROR("Failed retrieving entry for key \"%pV\"", fr_box_strvalue_len((char const *)key, key_len)); error: fr_redis_reply_free(reply); @@ -284,7 +274,6 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config redisReply *replies[5]; /* Should have the same number of elements as pipelined commands */ size_t reply_num = 0, i; - char *p; int cnt; vp_tmpl_t expires_value; @@ -372,12 +361,7 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config pipelined++; } - if (RDEBUG_ENABLED3) { - p = fr_asprint(request, (char const *)c->key, c->key_len, '\0'); - RDEBUG3("DEL \"%s\"", p); - talloc_free(p); - - } + RDEBUG3("DEL \"%pV\"", fr_box_strvalue_len((char const *)c->key, c->key_len)); if (redisAppendCommand(conn->handle, "DEL %b", c->key, c->key_len) != REDIS_OK) goto append_error; pipelined++; @@ -386,9 +370,7 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config RDEBUG3("argv command"); RINDENT(); for (i = 0; i < talloc_array_length(argv); i++) { - p = fr_asprint(request, argv[i], argv_len[i], '\0'); - RDEBUG3("%s", p); - talloc_free(p); + RDEBUG3("%pV", fr_box_strvalue_len(argv[i], argv_len[i])); } REXDENT(); } @@ -399,11 +381,8 @@ static cache_status_t cache_entry_insert(UNUSED rlm_cache_config_t const *config * Set the expiry time and close out the transaction. */ if (c->expires > 0) { - if (RDEBUG_ENABLED3) { - p = fr_asprint(request, (char const *)c->key, c->key_len, '\"'); - RDEBUG3("EXPIREAT \"%s\" %li", p, (long)c->expires); - talloc_free(p); - } + RDEBUG3("EXPIREAT \"%pV\" %li", + fr_box_strvalue_len((char const *)c->key, c->key_len), (long)c->expires); if (redisAppendCommand(conn->handle, "EXPIREAT %b %i", c->key, c->key_len, c->expires) != REDIS_OK) goto append_error; pipelined++; diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 7de0cb3b110..83340797082 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -220,13 +220,7 @@ static rlm_rcode_t cache_find(rlm_cache_entry_t **out, rlm_cache_t const *inst, break; case CACHE_MISS: - if (RDEBUG_ENABLED2) { - char *p; - - p = fr_asprint(request, (char const *)key, key_len, '"'); - RDEBUG("No cache entry found for \"%s\"", p); - talloc_free(p); - } + RDEBUG2("No cache entry found for \"%pV\"", fr_box_strvalue_len((char const *)key, key_len)); return RLM_MODULE_NOTFOUND; /* FALL-THROUGH */ @@ -243,27 +237,16 @@ static rlm_rcode_t cache_find(rlm_cache_entry_t **out, rlm_cache_t const *inst, * passed. Delete it, and pretend it doesn't exist. */ if ((c->expires < request->packet->timestamp.tv_sec) || (c->created < inst->config.epoch)) { - if (RDEBUG_ENABLED2) { - char *p; - - p = fr_asprint(request, (char const *)key, key_len, '"'); - RDEBUG2("Found entry for \"%s\", but it expired %li seconds ago. Removing it", p, - request->packet->timestamp.tv_sec - c->expires); - talloc_free(p); - } + RDEBUG2("Found entry for \"%pV\", but it expired %li seconds ago. Removing it", + fr_box_strvalue_len((char const *)key, key_len), + request->packet->timestamp.tv_sec - c->expires); inst->driver->expire(&inst->config, inst->driver_inst->data, request, handle, c->key, c->key_len); cache_free(inst, &c); return RLM_MODULE_NOTFOUND; /* Couldn't find a non-expired entry */ } - if (RDEBUG_ENABLED2) { - char *p; - - p = fr_asprint(request, (char const *)key, key_len, '"'); - RDEBUG2("Found entry for \"%s\"", p); - talloc_free(p); - } + RDEBUG2("Found entry for \"%pV\"", fr_box_strvalue_len((char const *)key, key_len)); c->hits++; *out = c; diff --git a/src/modules/rlm_csv/rlm_csv.c b/src/modules/rlm_csv/rlm_csv.c index 42f96d4f3b0..7f342209b4d 100644 --- a/src/modules/rlm_csv/rlm_csv.c +++ b/src/modules/rlm_csv/rlm_csv.c @@ -441,14 +441,11 @@ static int csv_map_getvalue(TALLOC_CTX *ctx, VALUE_PAIR **out, REQUEST *request, vp = fr_pair_afrom_da(ctx, da); rad_assert(vp); - if (fr_pair_value_from_str(vp, str, talloc_array_length(str) - 1) < 0) { - char *escaped; - - escaped = fr_asprint(vp, str, talloc_array_length(str) - 1, '\''); - RWDEBUG("Failed parsing value \"%s\" for attribute %s: %s", escaped, + if (fr_pair_value_from_str(vp, str, talloc_array_length(str) - 1, '\0', true) < 0) { + RWDEBUG("Failed parsing value \"%pV\" for attribute %s: %s", fr_box_strvalue_buffer(str), map->lhs->tmpl_da->name, fr_strerror()); + talloc_free(vp); - talloc_free(vp); /* also frees escaped */ return -1; } diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index 445bec7be7a..94103ed2fdf 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -279,12 +279,10 @@ static int _sql_map_proc_get_value(TALLOC_CTX *ctx, VALUE_PAIR **out, * Buffer not always talloced, sometimes it's * just a pointer to a field in a result struct. */ - if (fr_pair_value_from_str(vp, value, strlen(value)) < 0) { - char *escaped; - - escaped = fr_asprint(vp, value, talloc_array_length(value) - 1, '"'); - RPEDEBUG("Failed parsing value \"%s\" for attribute %s", escaped, map->lhs->tmpl_da->name); - talloc_free(vp); /* also frees escaped */ + if (fr_pair_value_from_str(vp, value, -1, '\0', true) < 0) { + RPEDEBUG("Failed parsing value \"%pV\" for attribute %s", + fr_box_strvalue_buffer(value), map->lhs->tmpl_da->name); + talloc_free(vp); return -1; }