BUG/MINOR: startup: hap_register_feature() fix for partial feature name
In patch 2fe4cbd8e ("MINOR: startup: allow hap_register_feature() to enable a feature in the list"), the ability to overwrite a '-' in the feature list was added. However the code was not tokenizing correctly the string, and partial feature name found in the name could result in having the same feature name multiple time. This patch rewrites the lookup of the string by tokenizing it correctly.
This commit is contained in:
parent
7268e9c249
commit
ab2fa95bdd
@ -347,7 +347,8 @@ void hap_register_feature(const char *name)
|
|||||||
static int must_free = 0;
|
static int must_free = 0;
|
||||||
int new_len = strlen(build_features) + 2 + strlen(name);
|
int new_len = strlen(build_features) + 2 + strlen(name);
|
||||||
char *new_features;
|
char *new_features;
|
||||||
char *found, *endp;
|
char *startp, *endp;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
new_features = malloc(new_len + 1);
|
new_features = malloc(new_len + 1);
|
||||||
if (!new_features)
|
if (!new_features)
|
||||||
@ -355,23 +356,39 @@ void hap_register_feature(const char *name)
|
|||||||
|
|
||||||
strlcpy2(new_features, build_features, new_len);
|
strlcpy2(new_features, build_features, new_len);
|
||||||
|
|
||||||
|
startp = new_features;
|
||||||
|
|
||||||
/* look if the string already exists */
|
/* look if the string already exists */
|
||||||
/* must be a complete feature name with a space of end of string behind (eg OPENSSL vs OPENSSL_AWSLC) */
|
while (startp) {
|
||||||
found = strstr(new_features, name);
|
char *sign = startp;
|
||||||
endp = found+strlen(name);
|
|
||||||
|
|
||||||
if (found && (*endp == ' ' || *endp == '\0')) {
|
/* tokenize for simpler strcmp */
|
||||||
|
endp = strchr(startp, ' ');
|
||||||
|
if (endp)
|
||||||
|
*endp = '\0';
|
||||||
|
|
||||||
/* if the feature name was found with a '-' replace it by a '+' */
|
startp++; /* skip sign */
|
||||||
if ((found-1 >= new_features) && (*(found-1) == '-')) {
|
|
||||||
*(found-1) = '+';
|
if (strcmp(startp, name) == 0) {
|
||||||
|
*sign = '+';
|
||||||
|
found = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
/* couldn't find a space, that's the end of the string */
|
||||||
/* if we didn't find the feature add it to the string */
|
if (!endp)
|
||||||
snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
|
break;
|
||||||
|
|
||||||
|
*endp = ' ';
|
||||||
|
startp = endp + 1;
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if we didn't find the feature add it to the string */
|
||||||
|
if (!found)
|
||||||
|
snprintf(new_features, new_len + 1, "%s +%s", build_features, name);
|
||||||
|
|
||||||
if (must_free)
|
if (must_free)
|
||||||
ha_free(&build_features);
|
ha_free(&build_features);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user