"git@developer.sourcefind.cn:OpenDAS/fastmoe.git" did not exist on "55f8ca7df44c14061af96f0c7be5049187033352"
Commit aa87a490 authored by Marvin Meiers's avatar Marvin Meiers Committed by Antoine Kaufmann
Browse files

lib: check length of socket paths in SimbricksBaseIf{Listen,Connect}

Check the length of socket paths in SimbricksBaseIfListen and
SimbricksBaseIfConnect. If the length exceeds the size of sun_path in
the sockaddr_un struct, we fail with a meaningful error message.

This resolves #42.
parent ec3ba41e
...@@ -191,6 +191,16 @@ int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if, ...@@ -191,6 +191,16 @@ int SimbricksBaseIfListen(struct SimbricksBaseIf *base_if,
int flags; int flags;
struct SimbricksBaseIfParams *params = &base_if->params; struct SimbricksBaseIfParams *params = &base_if->params;
/* make sure the socket path does not exceed the limits of saun.sun_path */
if (strlen(params->sock_path) >= sizeof(saun.sun_path)) {
fprintf(stderr,
"SimbricksBaseIfListen: socket path %s is too long "
"(exceeding %lu characters)\n",
params->sock_path, sizeof(saun.sun_path) - 1);
errno = ENAMETOOLONG;
return -1;
}
/* make sure we have enough space in the memory pool */ /* make sure we have enough space in the memory pool */
base_if->shm = pool; base_if->shm = pool;
size_t in_len = params->in_num_entries * params->in_entries_size; size_t in_len = params->in_num_entries * params->in_entries_size;
...@@ -259,6 +269,16 @@ int SimbricksBaseIfConnect(struct SimbricksBaseIf *base_if) { ...@@ -259,6 +269,16 @@ int SimbricksBaseIfConnect(struct SimbricksBaseIf *base_if) {
int flags; int flags;
struct SimbricksBaseIfParams *params = &base_if->params; struct SimbricksBaseIfParams *params = &base_if->params;
/* make sure the socket path does not exceed the limits of saun.sun_path */
if (strlen(params->sock_path) >= sizeof(saun.sun_path)) {
fprintf(stderr,
"SimbricksBaseIfConnect: socket path %s is too long "
"(exceeding %lu characters)\n",
params->sock_path, sizeof(saun.sun_path) - 1);
errno = ENAMETOOLONG;
return -1;
}
base_if->listener = false; base_if->listener = false;
if ((base_if->conn_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { if ((base_if->conn_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment