#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <stdlib.h>
#ifdef AFS_NT40_ENV
-#include <winsock2.h>
#include <direct.h>
#else
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <netdb.h>
#include <ctype.h>
#endif
-#include <string.h>
-#include <errno.h>
-#include "afsutil.h"
+#include "afsutil.h"
/* also parse a.b.c.d addresses */
struct hostent *
}
}
if (numeric) {
- tc = *ahost; /* look at the first char */
/* decimal address, return fake hostent with only hostaddr field good */
tval = 0;
dots = 0;
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--;
if (saveTmpDir == NULL) {
/* initialize global temporary directory string */
- char *dirp = (char *)malloc(MAX_PATH+1);
+ char *dirp = malloc(MAX_PATH+1);
int freeDirp = 1;
if (dirp != NULL) {