mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
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.
This commit is contained in:
parent
5288b2ad8e
commit
a44b23ba63
@ -2635,16 +2635,13 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
|
||||
if (virMutexInit(&updateMutex))
|
||||
return 1;
|
||||
|
||||
if (virNWFilterParamConfLayerInit())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void virNWFilterConfLayerShutdown(void)
|
||||
{
|
||||
virNWFilterParamConfLayerShutdown();
|
||||
virMutexDestroy(&updateMutex);
|
||||
}
|
||||
|
||||
|
||||
|
@ -568,9 +568,6 @@ void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
|
||||
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__, \
|
||||
|
@ -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(xmlNodePtr cur)
|
||||
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(virNWFilterHashTablePtr table,
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -50,4 +50,10 @@ int virNWFilterHashTablePutAll(virConnectPtr conn,
|
||||
virNWFilterHashTablePtr src,
|
||||
virNWFilterHashTablePtr dest);
|
||||
|
||||
# define VALID_VARNAME \
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||
|
||||
# define VALID_VARVALUE \
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:"
|
||||
|
||||
#endif /* NWFILTER_PARAMS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user