]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: guid: restrict guid format
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 27 Mar 2024 14:15:19 +0000 (15:15 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 5 Apr 2024 13:40:42 +0000 (15:40 +0200)
GUID format is unspecified to allow users to choose the naming scheme.
Some restrictions however are added by this patch, mainly to ensure
coherence and memory usage.

The first restriction is on the length of GUID. No more than 127
characters can be used to prevent memory over consumption.

The second restriction is on the character set allowed in GUID. Utility
function invalid_char() is used for this : it allows alphanumeric
values and '-', '_', '.' and ':'.

include/haproxy/guid-t.h
src/guid.c

index 41645d729d9dbd7ea12b7be2c15b118f0790a16d..9eea355d174e09ee03b481ff7b0ee814c625cc70 100644 (file)
@@ -4,6 +4,9 @@
 #include <import/ebtree-t.h>
 #include <haproxy/obj_type-t.h>
 
+/* Maximum GUID size excluding final '\0' */
+#define GUID_MAX_LEN 127
+
 struct guid_node {
        struct ebpt_node node;   /* attach point into GUID global tree */
        enum obj_type *obj_type; /* pointer to GUID obj owner */
index 178353ba53492a30f948cea759f1bd49b0a429cf..1f211642719c110e215e89b3d6cfca6032e61ede 100644 (file)
@@ -26,6 +26,18 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
        struct guid_node *dup;
        struct ebpt_node *node;
        char *dup_name = NULL;
+       const char *c;
+
+       if (strlen(uid) > GUID_MAX_LEN) {
+               memprintf(errmsg, "UID too big");
+               goto err;
+       }
+
+       c = invalid_char(uid);
+       if (c) {
+               memprintf(errmsg, "invalid character '%c'", c[0]);
+               goto err;
+       }
 
        switch (obj_type(objt)) {
        default:
@@ -52,6 +64,7 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
        return 0;
 
  err:
+       ALREADY_CHECKED(guid);
        ha_free(&guid->node.key);
        ha_free(&dup_name);
        return 1;