]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix more instances of manual escaping
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 30 May 2018 15:17:24 +0000 (21:17 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 30 May 2018 15:17:24 +0000 (21:17 +0600)
src/lib/ldap/map.c
src/lib/ldap/sasl_s.c
src/lib/redis/cluster.c
src/lib/redis/redis.c
src/modules/rlm_cache/drivers/rlm_cache_redis/rlm_cache_redis.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_csv/rlm_csv.c
src/modules/rlm_sql/rlm_sql.c

index 154d8f3e7296bed96359d087fb779aa3d2606528..619f15201867256fa9a1909d6ab3f0ecd9e13a69 100644 (file)
@@ -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;
index d2f0722cbff069ad397695e4ae009ecc02b32e24..834e79a44155f82052b458a255be7d46d1824197 100644 (file)
@@ -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);
                        }
                }
index 3e49842df0d45fc2301a56bbc17d056b10316279..a7be9cf800999ded488cdadb62c1d834e609dca7 100644 (file)
@@ -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;
        }
index 8a5e8fadd6cd09e9e6873c5711dc384bedbf71a5..09b9db25dba2bea9fef2851e29d37dcccd6bb7d0 100644 (file)
@@ -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);
index fd613319fd19fffd20f3d6a7cffc2a877e8b399e..cb48c563fb57ee639fadaa3cbaab2b2937ab167b 100644 (file)
@@ -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++;
index 7de0cb3b1103f655444256550d330d5445efbdfc..833407970827b1e92c8837f52f83af73cba2898d 100644 (file)
@@ -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;
index 42f96d4f3b0ea7ac508e45693908d08c13c8a84f..7f342209b4db1101e6d0df38597ee719f907a18e 100644 (file)
@@ -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;
        }
 
index 445bec7be7a39f44dead9d121a379f64a59c23ce..94103ed2fdf6b5ce94eb0a41424f31c32f3a94a2 100644 (file)
@@ -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;
        }