Get rid of the regular expressions when evaluating variable names and values. Rather use the strspn() function. Along with this cleanup the initialization function for the code that used the regular expression can also be removed. Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx> --- src/conf/nwfilter_conf.c | 5 ---- src/conf/nwfilter_conf.h | 3 -- src/conf/nwfilter_params.c | 50 +++++++++++++++------------------------------ src/conf/nwfilter_params.h | 6 +++++ 4 files changed, 24 insertions(+), 40 deletions(-) Index: libvirt-acl/src/conf/nwfilter_conf.h =================================================================== --- libvirt-acl.orig/src/conf/nwfilter_conf.h +++ libvirt-acl/src/conf/nwfilter_conf.h @@ -568,9 +568,6 @@ void virNWFilterPoolObjUnlock(virNWFilte int virNWFilterConfLayerInit(virHashIterator domUpdateCB); void virNWFilterConfLayerShutdown(void); -int virNWFilterParamConfLayerInit(void); -void virNWFilterParamConfLayerShutdown(void); - # define virNWFilterReportError(conn, code, fmt...) \ (void)conn; \ virReportErrorHelper(NULL, VIR_FROM_NWFILTER, code, __FILE__, \ Index: libvirt-acl/src/conf/nwfilter_params.c =================================================================== --- libvirt-acl.orig/src/conf/nwfilter_params.c +++ libvirt-acl/src/conf/nwfilter_params.c @@ -22,8 +22,6 @@ #include <config.h> -#include <regex.h> - #include "internal.h" #include "memory.h" @@ -35,13 +33,6 @@ #define VIR_FROM_THIS VIR_FROM_NWFILTER -/* - * regular expressions for parameter names and values - */ -static regex_t regex_nam; -static regex_t regex_val; - - static void hashDealloc(void *payload, const char *name ATTRIBUTE_UNUSED) { @@ -215,6 +206,21 @@ err_exit: #ifndef PROXY + +static bool +isValidVarName(const char *var) +{ + return var[strspn(var, VALID_VARNAME)] == 0; +} + + +static bool +isValidVarValue(const char *value) +{ + return value[strspn(value, VALID_VARVALUE)] == 0; +} + + virNWFilterHashTablePtr virNWFilterParseParamAttributes(xmlNodePtr cur) { @@ -234,9 +240,9 @@ virNWFilterParseParamAttributes(xmlNodeP nam = virXMLPropString(cur, "name"); val = virXMLPropString(cur, "value"); if (nam != NULL && val != NULL) { - if (regexec(®ex_nam, nam, 0, NULL, 0) != 0) + if (!isValidVarName(nam)) goto skip_entry; - if (regexec(®ex_val, val, 0, NULL, 0) != 0) + if (!isValidVarValue(nam)) goto skip_entry; if (virNWFilterHashTablePut(table, nam, val, 1)) { VIR_FREE(nam); @@ -296,25 +302,3 @@ virNWFilterFormatParamAttributes(virNWFi return virBufferContentAndReset(&buf); } - - -int virNWFilterParamConfLayerInit(void) { - - if (regcomp(®ex_nam, "^[a-zA-Z0-9_]+$" , - REG_NOSUB|REG_EXTENDED) != 0) - return 1; - - if (regcomp(®ex_val, "^[a-zA-Z0-9_.:]+$", - REG_NOSUB|REG_EXTENDED) != 0) { - regfree(®ex_nam); - return 1; - } - - return 0; -} - - -void virNWFilterParamConfLayerShutdown(void) { - regfree(®ex_nam); - regfree(®ex_val); -} Index: libvirt-acl/src/conf/nwfilter_params.h =================================================================== --- libvirt-acl.orig/src/conf/nwfilter_params.h +++ libvirt-acl/src/conf/nwfilter_params.h @@ -50,4 +50,10 @@ int virNWFilterHashTablePutAll(virConnec virNWFilterHashTablePtr src, virNWFilterHashTablePtr dest); +#define VALID_VARNAME \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" + +#define VALID_VARVALUE \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:" + #endif /* NWFILTER_PARAMS_H */ Index: libvirt-acl/src/conf/nwfilter_conf.c =================================================================== --- libvirt-acl.orig/src/conf/nwfilter_conf.c +++ libvirt-acl/src/conf/nwfilter_conf.c @@ -2634,16 +2634,13 @@ int virNWFilterConfLayerInit(virHashIter if (virMutexInit(&updateMutex)) return 1; - if (virNWFilterParamConfLayerInit()) - return 1; - return 0; } void virNWFilterConfLayerShutdown(void) { - virNWFilterParamConfLayerShutdown(); + virMutexDestroy(&updateMutex); } -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list