Fixed certificates loading on startup with some filesystems.

It appears that readdir() on Linux detects file types unreliably, always setting
the "d_type" field to DT_UNKNOWN for some less common filesystems.  As a result,
all files were skipped and no certificate bundles were found when the state
directory was located on such filesystems.

Skipping "." and ".." instead of any non-regular files should be enough, as no
other non-regular files normally appear in this directory.

This closes #368 issue on GitHub.
This commit is contained in:
Valentin Bartenev
2021-03-15 14:57:31 +03:00
parent a1107e859b
commit b0a1266835
2 changed files with 13 additions and 4 deletions

View File

@@ -30,6 +30,13 @@ reconfiguring an application; the bug had appeared in 1.19.0.
</para>
</change>
<change type="bugfix">
<para>
persistent storage of certificates might've not worked with some filesystems in
Linux, and all uploaded certificate bundles were forgotten after restart.
</para>
</change>
</changes>

View File

@@ -838,7 +838,12 @@ nxt_cert_store_load(nxt_task_t *task, nxt_mp_t *mp)
break;
}
if (de->d_type != DT_REG) {
nxt_debug(task, "readdir(\"%s\"): \"%s\"", rt->certs.start, de->d_name);
name.length = nxt_strlen(de->d_name);
name.start = (u_char *) de->d_name;
if (nxt_str_eq(&name, ".", 1) || nxt_str_eq(&name, "..", 2)) {
continue;
}
@@ -849,9 +854,6 @@ nxt_cert_store_load(nxt_task_t *task, nxt_mp_t *mp)
item->fd = -1;
name.length = nxt_strlen(de->d_name);
name.start = (u_char *) de->d_name;
size = rt->certs.length + name.length + 1;
if (size > alloc) {