Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions apps/wolfsshd/test/test_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,9 @@ static int test_ConfigSavePID(void)
void (*prevXfsz)(int);
#endif

/* Every path below lives in this directory, which mkdtemp() creates mode
* 0700. No other user can traverse it, so none of the path-based checks
* here can be raced. */
if (mkdtemp(base) == NULL) {
Log(" mkdtemp failed.\n");
ret = WS_FATAL_ERROR;
Expand All @@ -2773,15 +2776,16 @@ static int test_ConfigSavePID(void)
ret = pidSave(conf, pidPath);
}
if (ret == WS_SUCCESS) {
if (stat(pidPath, &st) != 0) {
/* fstat() the open handle instead of stat()ing the path a second
* time, so the mode asserted below belongs to the same file the PID
* was read from. */
f = fopen(pidPath, "r");
if (f == NULL || fstat(fileno(f), &st) != 0) {
Log(" Could not open or stat %s.\n", pidPath);
ret = WS_FATAL_ERROR;
}
else {
f = fopen(pidPath, "r");
rd = (f != NULL) ? fscanf(f, "%ld", &pid) : 0;
if (f != NULL) {
fclose(f);
}
rd = fscanf(f, "%ld", &pid);
ret = smExpect("normal PID file written with our PID",
(rd == 1 && pid == (long)getpid()) ? WS_SUCCESS
: WS_FATAL_ERROR, 1);
Expand All @@ -2791,6 +2795,9 @@ static int test_ConfigSavePID(void)
: WS_SUCCESS, 1);
}
}
if (f != NULL) {
fclose(f);
}
}

/* Scenario 2: a symlink at the PID path is refused, link target untouched.
Expand Down Expand Up @@ -2897,15 +2904,13 @@ static int test_ConfigSavePID(void)
}
if (ret == WS_SUCCESS) {
pid = -1;
if (stat(stale, &st) != 0) {
f = fopen(stale, "r");
if (f == NULL || fstat(fileno(f), &st) != 0) {
Log(" Could not open or stat %s.\n", stale);
ret = WS_FATAL_ERROR;
}
else {
f = fopen(stale, "r");
rd = (f != NULL) ? fscanf(f, "%ld", &pid) : 0;
if (f != NULL) {
fclose(f);
}
rd = fscanf(f, "%ld", &pid);
ret = smExpect("existing PID file rewritten with our PID",
(rd == 1 && pid == (long)getpid()) ? WS_SUCCESS
: WS_FATAL_ERROR, 1);
Expand All @@ -2916,6 +2921,9 @@ static int test_ConfigSavePID(void)
: WS_SUCCESS, 1);
}
}
if (f != NULL) {
fclose(f);
}
}

/* Scenario 6: a PID file owned by another user is refused instead of being
Expand Down
12 changes: 5 additions & 7 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3113,20 +3113,18 @@ int CheckAlgoList(const char* list, byte type)
byte id = NameToIdType(name, nameSz, &tokenType);

if (id == ID_NONE) {
int noneOk = 0;

/* "none" names the null cipher/MAC, not a host key. It
* disables the transport, so it needs the build flag. */
#ifdef WOLFSSH_ALLOW_NONE_CIPHER
if (type == TYPE_CIPHER || type == TYPE_MAC) {
noneOk = 1;
}
#endif
if (!noneOk) {
if (type != TYPE_CIPHER && type != TYPE_MAC) {
ret = WS_INVALID_ALGO_ID;
break;
}
usableCount++;
#else
ret = WS_INVALID_ALGO_ID;
break;
#endif
}
else if (id != ID_UNKNOWN) {
/* Wrong category is a caller mistake, not a build
Expand Down
Loading