>
> On 10/31/14 00:54, [email protected] wrote:
> > +int set_rdma_device_names(const char *hostname) {
> > + DIR *class_dir;
> > + struct dirent *dent;
> > +
> > + class_dir = opendir(SYS_INFINIBAND);
> > + if (!class_dir) {
> > + syslog(LOG_INFO, "Failed to open %s", SYS_INFINIBAND);
> > + return -ENOSYS;
> > + }
> > +
> > + while ((dent = readdir(class_dir))) {
> > + int retry = set_retry_cnt;
> > + if (dent->d_name[0] == '.')
> > + continue;
> > +
> > + while (update_node_desc(dent->d_name, hostname) && retry
> > 0) {
> > + syslog(LOG_ERR, "retrying set Node Description on
> %s\n",
> > + dent->d_name);
> > + retry--;
> > + }
> > + }
> > +
> > + return 0;
> > +}
>
> Has this code been tested with Valgrind and --track-fds=yes and --leak-
> check=full ? I see an opendir() call in the above code but no closedir().
Great catch thanks!
I'll run with valgrind on v2.
>
> > +int read_and_set_hostname(int fd)
> > +{
> > + int rc;
> > + char buf[128];
> > + if (read(fd, buf, 65) >= 0) {
> > + buf[65] = '\0';
> > + newline_to_null(buf);
> > + strip_domain(buf);
> > + syslog(LOG_INFO, "new hostname detected: %s", buf);
> > + set_rdma_device_names((char *)buf);
> > + rc = 0;
> > + } else {
> > + syslog(LOG_ERR, "Read %s Failed\n", SYS_HOSTNAME);
> > + rc = -EIO;
> > + }
> > + return rc;
> > +}
>
> The above code will trigger reading uninitialized data if the data read from
> fd
> is not newline-terminated and less than 65 characters are read.
I'm not sure what you mean. Do you mean "will trigger _using_ uninitialized
data"?
How about the following?
@@ -155,8 +156,8 @@ int read_and_set_hostname(int fd)
{
int rc;
char buf[128];
- if (read(fd, buf, 65) >= 0) {
- buf[65] = '\0';
+ memset(buf, 0, sizeof(buf));
+ if (read(fd, buf, 64) >= 0) {
newline_to_null(buf);
strip_domain(buf);
syslog(LOG_INFO, "new hostname detected: %s", buf);
Ira
>
> Bart.
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the
> body
> of a message to [email protected] More majordomo info at
> http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html