mirror of https://github.com/wolfSSL/wolfssh.git
cast on values and adjust isspace check
parent
97974e9af2
commit
17f3a029e3
|
@ -434,26 +434,28 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value)
|
||||||
const char *ptr2;
|
const char *ptr2;
|
||||||
const char *postfix = NULL;
|
const char *postfix = NULL;
|
||||||
const char *prefix = NULL;
|
const char *prefix = NULL;
|
||||||
int prefix_len = 0;
|
int prefixLen = 0;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
/* No value, nothing to do */
|
/* No value, nothing to do */
|
||||||
if (!value || value[0] == '\0') {
|
if (!value || value[0] == '\0') {
|
||||||
return WS_BAD_ARGUMENT;
|
return WS_BAD_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore trailing whitespace */
|
/* Ignore trailing whitespace */
|
||||||
ptr = value + strlen(value) - 1;
|
ptr = value + WSTRLEN(value) - 1;
|
||||||
while(ptr != value) {
|
while (ptr != value) {
|
||||||
if (!isspace(value)) {
|
if (!isspace(*ptr)) {
|
||||||
ptr--;
|
ptr--;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find wildcards */
|
/* Find wildcards */
|
||||||
ptr2 = ptr;
|
ptr2 = ptr;
|
||||||
while(ptr2 != value) {
|
while (ptr2 != value) {
|
||||||
if (*ptr2 == '*') {
|
if (*ptr2 == '*') {
|
||||||
/* Wildcard found */
|
/* Wildcard found */
|
||||||
found = 1;
|
found = 1;
|
||||||
|
@ -469,6 +471,7 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value)
|
||||||
ptr2--;
|
ptr2--;
|
||||||
}
|
}
|
||||||
ptr = ptr2;
|
ptr = ptr2;
|
||||||
|
|
||||||
/* Use wildcard */
|
/* Use wildcard */
|
||||||
if (found) {
|
if (found) {
|
||||||
#ifdef __unix__
|
#ifdef __unix__
|
||||||
|
@ -491,13 +494,13 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value)
|
||||||
memcpy(path, value, ptr2 - value);
|
memcpy(path, value, ptr2 - value);
|
||||||
path[ptr2 - value] = '\0';
|
path[ptr2 - value] = '\0';
|
||||||
prefix = ptr2 + 1;
|
prefix = ptr2 + 1;
|
||||||
prefix_len = ptr - ptr2 - 1;
|
prefixLen = (int)(ptr - ptr2 - 1);
|
||||||
} else {
|
} else {
|
||||||
path = WMALLOC(2, NULL, 0);
|
path = WMALLOC(2, NULL, 0);
|
||||||
memcpy(path, ".", 1);
|
memcpy(path, ".", 1);
|
||||||
path[1] = '\0';
|
path[1] = '\0';
|
||||||
prefix = value;
|
prefix = value;
|
||||||
prefix_len = ptr - value;
|
prefixLen = (int)(ptr - value);
|
||||||
}
|
}
|
||||||
|
|
||||||
d = opendir(path);
|
d = opendir(path);
|
||||||
|
@ -509,21 +512,21 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Check if filename prefix matches */
|
/* Check if filename prefix matches */
|
||||||
if (prefix_len > 0) {
|
if (prefixLen > 0) {
|
||||||
if (strlen(dir->d_name) <= prefix_len) {
|
if ((int)WSTRLEN(dir->d_name) <= prefixLen) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp(dir->d_name, prefix, prefix_len) != 0) {
|
if (WSTRNCMP(dir->d_name, prefix, prefixLen) != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (postfix) {
|
if (postfix) {
|
||||||
/* Skip if file is too short */
|
/* Skip if file is too short */
|
||||||
if (strlen(dir->d_name) <= strlen(postfix)) {
|
if (WSTRLEN(dir->d_name) <= WSTRLEN(postfix)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strncmp(dir->d_name + strlen(dir->d_name) -
|
if (WSTRNCMP(dir->d_name + WSTRLEN(dir->d_name) -
|
||||||
strlen(postfix), postfix, strlen(postfix))
|
WSTRLEN(postfix), postfix, WSTRLEN(postfix))
|
||||||
== 0) {
|
== 0) {
|
||||||
snprintf(filepath, PATH_MAX, "%s/%s", path,
|
snprintf(filepath, PATH_MAX, "%s/%s", path,
|
||||||
dir->d_name);
|
dir->d_name);
|
||||||
|
@ -551,6 +554,8 @@ static int HandleInclude(WOLFSSHD_CONFIG *conf, const char *value)
|
||||||
}
|
}
|
||||||
WFREE(filepath, NULL, 0);
|
WFREE(filepath, NULL, 0);
|
||||||
#else
|
#else
|
||||||
|
(void)prefixLen;
|
||||||
|
(void)prefix;
|
||||||
/* Don't support wildcards here */
|
/* Don't support wildcards here */
|
||||||
return WS_BAD_ARGUMENT;
|
return WS_BAD_ARGUMENT;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue