#include "mtr.h"
#include "asn.h"
-
+#include "utils.h"
//#define IIDEBUG
#ifdef IIDEBUG
txt = (char*)txtrec;
pt++;
- strncpy(txt, (char*) pt, txtlen);
+ xstrncpy(txt, (char*) pt, txtlen);
txt[txtlen] = 0;
if (iihash)
#include "dns.h"
#include "asn.h"
#include "display.h"
+#include "utils.h"
#endif
}
}
buf[i] = '\0';
- if ( strlen( buf ) > 0 ) strcpy( ctl->fld_active, buf );
+ if ( strlen( buf ) > 0 )
+ xstrncpy(ctl->fld_active, buf, 2 * MAXFLD);
return ActionNone;
}
if (tolower(c) == 'j') {
if( strchr(ctl->fld_active, 'N') ) {
- strcpy(ctl->fld_active, "DR AGJMXI"); /* GeoMean and jitter */
+ xstrncpy(ctl->fld_active, "DR AGJMXI", 2 * MAXFLD); /* GeoMean and jitter */
} else {
- strcpy(ctl->fld_active, "LS NABWV"); /* default */
+ xstrncpy(ctl->fld_active, "LS NABWV", 2 * MAXFLD); /* default */
}
return ActionNone;
}
error(EXIT_FAILURE, 0, "Unknown field identifier: %c", optarg[i]);
}
}
- strcpy ((char*)ctl->fld_active, optarg);
+ xstrncpy(ctl->fld_active, optarg, 2 * MAXFLD);
break;
case 'B':
ctl->bitpattern = strtonum_or_err(optarg, "invalid argument", STRTO_INT);
ctl.maxTTL = 30;
ctl.maxUnknown = 12;
ctl.tcp_timeout = 10 * 1000000;
- strcpy(ctl.fld_active, "LS NABWV");
+ xstrncpy(ctl.fld_active, "LS NABWV", 2 * MAXFLD);
/* Get the raw sockets first thing, so we can drop to user euid immediately */
ctl.Hostname = names->name;
// if (Hostname == NULL) Hostname = "localhost"; // no longer necessary.
if (gethostname(ctl.LocalHostname, sizeof(ctl.LocalHostname))) {
- strcpy(ctl.LocalHostname, "UNKNOWNHOST");
+ xstrncpy(ctl.LocalHostname, "UNKNOWNHOST", sizeof(ctl.LocalHostname));
}
if (net_preopen_result != 0) {
#include "net.h"
#include "display.h"
#include "dns.h"
+#include "utils.h"
static int packetsize; /* packet size used by ping */
static int spacketsize; /* packet size used by sendto */
switch ( saddr->sa_family ) {
case AF_INET:
sa4 = (struct sockaddr_in *) saddr;
- strncpy( strptr, inet_ntoa( sa4->sin_addr ), len - 1 );
+ xstrncpy( strptr, inet_ntoa( sa4->sin_addr ), len - 1 );
strptr[ len - 1 ] = '\0';
return;
#ifdef ENABLE_IPV6
#include "net.h"
#include "split.h"
+#include "utils.h"
#ifdef HAVE_NCURSES
# if defined(HAVE_NCURSES_H)
} else {
printf("%d %s\n", at+1, newLine);
fflush(stdout);
- strcpy(Lines[at], newLine);
+ xstrncpy(Lines[at], newLine, MAX_LINE_SIZE);
if (LineCount < (at+1)) {
LineCount = at+1;
}
#endif
LineCount = -1;
for (i=0; i<MAX_LINE_COUNT; i++) {
- strcpy(Lines[i], "???");
+ xstrncpy(Lines[i], "???", MAX_LINE_SIZE);
}
}
extern char *trim(char *s);
extern int strtonum_or_err(const char *str, const char *errmesg, const int type);
extern float strtofloat_or_err(const char *str, const char *errmesg);
+
+/* Like strncpy(3) but ensure null termination. */
+static inline void xstrncpy(char *dest, const char *src, size_t n)
+{
+ strncpy(dest, src, n - 1);
+ dest[n - 1] = 0;
+}