return NULL;
#endif
th = gethostbyaddr((void *)&addr, sizeof(addr), AF_INET);
- if (th) {
- strcpy(tbuffer, th->h_name);
+ if (th && strlen(th->h_name) < sizeof(tbuffer)) {
+ strlcpy(tbuffer, th->h_name, sizeof(tbuffer));
} else {
addr = ntohl(addr);
sprintf(tbuffer, "%d.%d.%d.%d", (int)((addr >> 24) & 0xff),
** w.x.y.z # machineName
** returns the network interface in network byte order
*/
+
+#define MAXBYTELEN 32
afs_uint32
extractAddr(char *line, int maxSize)
{
- char byte1[32], byte2[32], byte3[32], byte4[32];
+ char byte1[MAXBYTELEN], byte2[MAXBYTELEN];
+ char byte3[MAXBYTELEN], byte4[MAXBYTELEN];
int i = 0;
char *endPtr;
afs_uint32 val1, val2, val3, val4;
while ((*line != '.') && maxSize) { /* extract first byte */
if (!isdigit(*line))
return AFS_IPINVALID;
- if (i > 31)
+ if (i >= MAXBYTELEN-1)
return AFS_IPINVALID; /* no space */
byte1[i++] = *line++;
maxSize--;
while ((*line != '.') && maxSize) { /* extract second byte */
if (!isdigit(*line))
return AFS_IPINVALID;
- if (i > 31)
+ if (i >= MAXBYTELEN-1)
return AFS_IPINVALID; /* no space */
byte2[i++] = *line++;
maxSize--;
while ((*line != '.') && maxSize) {
if (!isdigit(*line))
return AFS_IPINVALID;
- if (i > 31)
+ if (i >= MAXBYTELEN-1)
return AFS_IPINVALID; /* no space */
byte3[i++] = *line++;
maxSize--;
while (*line && !isspace(*line) && maxSize) {
if (!isdigit(*line))
return AFS_IPINVALID;
- if (i > 31)
+ if (i >= MAXBYTELEN-1)
return AFS_IPINVALID; /* no space */
byte4[i++] = *line++;
maxSize--;