]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: opentracing: remove the last two occurrences of strncat()
authorWilly Tarreau <w@1wt.eu>
Fri, 7 Apr 2023 13:38:58 +0000 (15:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Apr 2023 16:14:28 +0000 (18:14 +0200)
In flt_ot_sample_to_str() there were two occurrences of strncat() which
are used to copy N chars from the source and append a zero. For the sake
of definitely getting rid of this nasty function let's replace them by
memcpy() instead. It's worth noting that the length test there appeared
to be incorrect as it didn't make provisions for the trailing zero,
unless the size argument doesn't take it into account (seems unlikely).
Nothing was changed regarding this. If the code was good, it still is,
otherwise if it was bad it still is. At least this is more obvious now
than when using a function that needs n+1 chars to work.

addons/ot/src/util.c

index 767685ea96ffc30dd888b2da0af9d71bf5e2e344..fd040164d55f2ad71d3caf33b42c8dd23d71f3e0 100644 (file)
@@ -553,8 +553,8 @@ int flt_ot_sample_to_str(const struct sample_data *data, char *value, size_t siz
                }
                else if (data->u.str.data > 0) {
                        retval = data->u.str.data;
-
-                       (void)strncat(value, data->u.str.area, retval);
+                       memcpy(value, data->u.str.area, retval);
+                       value[retval] = '\0';
                }
                else {
                        /*
@@ -615,8 +615,8 @@ int flt_ot_sample_to_str(const struct sample_data *data, char *value, size_t siz
                        FLT_OT_ERR("sample data size too large");
                } else {
                        retval = data->u.meth.str.data;
-
-                       (void)strncat(value, data->u.meth.str.area, retval);
+                       memcpy(value, data->u.meth.str.area, retval);
+                       value[retval] = '\0';
                }
        }
        else {