<div dir="ltr"><div>From: Yicheng Qin <<a href="mailto:yichengq@google.com">yichengq@google.com</a>></div><div>Subject: [PATCH] test/zdtm/sockets_dgram: check the length of path used</div><div><br></div><div>Path generated in the test is copied into sun_path attribute in</div>
<div>struct sockaddr_un. Additional check on whether sun_path can</div><div>contain the whole path is added. It is useful because if sun_path</div><div>can only contain the first part of the path, all sockadd_un</div><div>
will point to the same location, which leads to error.</div><div><br></div><div>Signed-off-by: Yicheng Qin <<a href="mailto:yichengq@google.com">yichengq@google.com</a>></div><div>---</div><div> test/zdtm/live/static/sockets_dgram.c | 12 ++++++++++++</div>
<div> 1 file changed, 12 insertions(+)</div><div><br></div><div>diff --git a/test/zdtm/live/static/sockets_dgram.c b/test/zdtm/live/static/sockets_dgram.c</div><div>index b914111..1df0570 100644</div><div>--- a/test/zdtm/live/static/sockets_dgram.c</div>
<div>+++ b/test/zdtm/live/static/sockets_dgram.c</div><div>@@ -73,18 +73,30 @@ int main(int argc, char *argv[])</div><div> </div><div> snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename);</div><div>
unlink(path);</div><div>+ if (strlen(path) >= sizeof(name_bound.sun_path)) {</div><div>+ fail("too long path");</div><div>+ exit(1);</div><div>+ }</div><div> </div>
<div> name_bound.sun_family = AF_UNIX;</div><div> strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path));</div><div> </div><div> snprintf(path, sizeof(path), "%s/%s.conn", cwd, filename);</div>
<div> unlink(path);</div><div>+ if (strlen(path) >= sizeof(name_conn.sun_path)) {</div><div>+ fail("too long path");</div><div>+ exit(1);</div><div>+ }</div><div>
</div><div> name_conn.sun_family = AF_UNIX;</div><div> strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path));</div><div> </div><div> snprintf(path, sizeof(path), "%s/%s.bound-conn", cwd, filename);</div>
<div> unlink(path);</div><div>+ if (strlen(path) >= sizeof(name_bound_conn.sun_path)) {</div><div>+ fail("too long path");</div><div>+ exit(1);</div><div>+ }</div>
<div> </div><div> name_bound_conn.sun_family = AF_UNIX;</div><div> strncpy(name_bound_conn.sun_path, path, sizeof(name_bound_conn.sun_path));</div></div>