Re: [PATCH 2/6] nfs-utils: store the address given in the upcall for later use

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Apr 1, 2009, at 1:06 PM, Jeff Layton wrote:
On Wed, 1 Apr 2009 12:58:09 -0400
Chuck Lever <chuck.lever@xxxxxxxxxx> wrote:

+	if (!addrstr_to_sockaddr(addr, address, port))
		goto fail;
-	}
-	if (!(*servername = calloc(strlen(ent->h_name) + 1, 1)))
+
+	*servername = sockaddr_to_hostname(addr, address);
+	if (*servername == NULL)
		goto fail;
-	memcpy(*servername, ent->h_name, strlen(ent->h_name));
-	snprintf(buf, INFOBUFLEN, "%s@%s", service, ent->h_name);
+
+	snprintf(buf, INFOBUFLEN, "%s@%s", service, *servername);

You should check the return code here.  It should be not greater than
INFOBUFLEN.


Do we really need to do this? Doesn't using snprintf guarantee that
it won't be?

The point of the check is to see if a buffer overflow _would_ have occurred. If the string was larger than the buffer, then we know either the service or *servername is somehow invalid (like not terminated with '\0'). Or, perhaps some error occurred inside snprintf.

Either way, you should check the return code here.

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux