Commit de0c3b95 authored by Yicheng Qin's avatar Yicheng Qin Committed by Pavel Emelyanov

test/zdtm/sockets_dgram: check the length of path used

Path generated in the test is copied into sun_path attribute in
struct sockaddr_un. Additional check on whether sun_path can
contain the whole path is added. It is useful because if sun_path
can only contain the first part of the path, all sockadd_un
will point to the same location, which leads to error.
Signed-off-by: 's avatarYicheng Qin <yichengq@google.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b95407e2
...@@ -73,18 +73,30 @@ int main(int argc, char *argv[]) ...@@ -73,18 +73,30 @@ int main(int argc, char *argv[])
snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename); snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_bound.sun_path)) {
fail("too long path");
exit(1);
}
name_bound.sun_family = AF_UNIX; name_bound.sun_family = AF_UNIX;
strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path)); strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path));
snprintf(path, sizeof(path), "%s/%s.conn", cwd, filename); snprintf(path, sizeof(path), "%s/%s.conn", cwd, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_conn.sun_path)) {
fail("too long path");
exit(1);
}
name_conn.sun_family = AF_UNIX; name_conn.sun_family = AF_UNIX;
strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path)); strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path));
snprintf(path, sizeof(path), "%s/%s.bound-conn", cwd, filename); snprintf(path, sizeof(path), "%s/%s.bound-conn", cwd, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_bound_conn.sun_path)) {
fail("too long path");
exit(1);
}
name_bound_conn.sun_family = AF_UNIX; name_bound_conn.sun_family = AF_UNIX;
strncpy(name_bound_conn.sun_path, path, sizeof(name_bound_conn.sun_path)); strncpy(name_bound_conn.sun_path, path, sizeof(name_bound_conn.sun_path));
......
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