From: Roger Wolff Date: Mon, 7 Apr 2008 00:00:00 +0000 (+0000) Subject: mtr v0.73 X-Git-Tag: v0.73^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de3d6bc16efea7e63910cce568498eed0e2cf45a;p=thirdparty%2Fmtr.git mtr v0.73 - Some securty patches. Although MTR drops privileges as soon as possible after opening the sockets, it still had some sprintf calls, which have now been converted into snprintf. source: ftp://ftp.bitwizard.nl/mtr/mtr-0.73.tar.gz --- diff --git a/NEWS b/NEWS index 4b2967b..faeeb60 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ WHAT'S NEW? + v0.72 Fix signed/unsigned bug in IPV6 part + improved random packet size behaviour. --REW + v0.71 Some IPV6 fixes, introduce packet size cmdline option. + (was already present as a cmdline argument) v0.70 Antinio submitted a cumulative patch containing some nice improvements. He also submitted an automake patch that causes mtr to no longer compile on my system. I diff --git a/TODO b/TODO index 381e6f9..ffc0ca3 100644 --- a/TODO +++ b/TODO @@ -61,8 +61,7 @@ Oh, Feel free to provide suggestions for this list. - Show state ("looking up host") while doing the DNS lookup for a new host. - - Read environment variable "MTR_DEFAULTS" as a commandline before - parsing the commandline. -- DONE. (ok it's MTR_OPTIONS.) + - to have a choice of icmp, tcp, and udp pings. -- Matt Martini - Autoconf 2.13 has a neat function that can be used to find the res_init function: @@ -86,6 +85,12 @@ Oh, Feel free to provide suggestions for this list. hops from the host I'm monitoring, MTR wastes a lot of screen real estate. -- Jacob Elder + - Colors in the curses version. -- Amix + + - If we run a mtr to monitor a connection it would be nice if the time at + which mtr was started is print somewhere. -- Sebastian Ganschow + + ------------------------------------------------------------------------ @@ -109,3 +114,7 @@ Things that shouldn't be on the TODO list because they're done. ;-) slowly (relative to the RTT time to the end host), it can probe all hosts in the first "round". -- DONE. + + - Read environment variable "MTR_DEFAULTS" as a commandline before + parsing the commandline. -- DONE. (ok it's MTR_OPTIONS.) + diff --git a/configure.in b/configure.in index 9e3bd52..2f89aa7 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT(mtr.c) -AM_INIT_AUTOMAKE(mtr, 0.72) +AM_INIT_AUTOMAKE(mtr, 0.73) AC_SUBST(GTK_OBJ) @@ -89,7 +89,11 @@ AC_CHECK_FUNC(res_mkquery, , AC_CHECK_LIB(bind, res_mkquery, , AC_CHECK_LIB(resolv, res_mkquery, , AC_CHECK_LIB(resolv, __res_mkquery, , AC_MSG_ERROR(No resolver library found))))) -LIBS="$LIBS -lresolv" +# This next line would override the just detected-or-not -lresolv. +# This apparently hurts BSD. And it's bad practise. So it should go. +# However, it probably didn't get added for nothing..... Holler if +# removing it hurts your OS.... -- REW +#LIBS="$LIBS -lresolv" AC_CHECK_FUNC(herror, , AC_DEFINE(NO_HERROR)) AC_CHECK_FUNC(strerror, , AC_DEFINE(NO_STRERROR)) @@ -99,6 +103,19 @@ AC_CHECK_FUNC(getaddrinfo, AC_DEFINE([ENABLE_IPV6], [], [Define to enable IPv6]) fi]) +AC_CHECK_DECLS(errno, , , [[ +#include +#include +]] ) + +AC_CHECK_TYPE(socklen_t, AC_DEFINE([HAVE_SOCKLEN_T], [], [Define if your system has socklen_t]) , , [[ +#include +]]) + +AC_CHECK_TYPE(struct in_addr, AC_DEFINE([HAVE_STRUCT_INADDR], [], [Define if you have struct in_addr]), , [[ +#include +]]) + dnl Add C flags to display more warnings AC_MSG_CHECKING(for C flags to get more warnings) ac_save_CFLAGS="$CFLAGS" diff --git a/curses.c b/curses.c index 03157a2..23c3b4e 100644 --- a/curses.c +++ b/curses.c @@ -19,6 +19,7 @@ #include #include +#include #ifndef NO_CURSES #include @@ -93,6 +94,7 @@ int mtr_curses_keyaction(void) { int c = getch(); int i=0; + float f = 0.0; char buf[MAXFLD+1]; if(c == 'q') @@ -169,10 +171,13 @@ int mtr_curses_keyaction(void) buf[i++] = c; /* need more checking on 'c' */ } buf[i] = '\0'; - i = atoi( buf ); - if ( i < 1 ) return ActionNone; - WaitTime = (float) i; + f = atof( buf ); + + if (f <= 0.0) return ActionNone; + if (getuid() != 0 && f < 1.0) + return ActionNone; + WaitTime = f; return ActionNone; } diff --git a/display.h b/display.h index d75c27b..2c96171 100644 --- a/display.h +++ b/display.h @@ -19,9 +19,11 @@ #include +/* Don't put a trailing comma in enumeration lists. Some compilers + (notably the one on Irix 5.2) do not like that. -- REW */ enum { ActionNone, ActionQuit, ActionReset, ActionDisplay, ActionClear, ActionPause, ActionResume, ActionDNS, - ActionScrollDown, ActionScrollUp, }; + ActionScrollDown, ActionScrollUp }; enum { DisplayReport, DisplayCurses, DisplayGTK, DisplaySplit, DisplayRaw, DisplayXML, DisplayCSV, DisplayTXT}; diff --git a/dns.c b/dns.c index ef3e518..9c48b45 100644 --- a/dns.c +++ b/dns.c @@ -32,6 +32,7 @@ #include #include #include +#define BIND_8_COMPAT #include #include #include @@ -54,8 +55,10 @@ extern char *sys_errlist[]; #define strerror(errno) (((errno) >= 0 && (errno) < sys_nerr) ? sys_errlist[errno] : "unlisted error") #endif +#if !HAVE_DECL_ERRNO /* Hmm, it seems Irix requires this */ extern int errno; +#endif extern int af; @@ -160,12 +163,15 @@ char *rrtypes[] = { "Resource reference", }; + +/* Please don't use a trailing comma in enumerations: It doesn't + work on all compilers -- REW */ enum { RR_UNKNOWN, RR_QUERY, RR_ANSWER, RR_AUTHORITY, - RR_RESOURCE, + RR_RESOURCE }; typedef struct { @@ -230,7 +236,7 @@ enum { STATE_FAILED, STATE_PTRREQ1, STATE_PTRREQ2, - STATE_PTRREQ3, + STATE_PTRREQ3 }; #define Is_PTR(x) ((x->state == STATE_PTRREQ1) || (x->state == STATE_PTRREQ2) || (x->state == STATE_PTRREQ3)) diff --git a/gtk.c b/gtk.c index 63e43e5..356a271 100644 --- a/gtk.c +++ b/gtk.c @@ -306,8 +306,8 @@ void gtk_set_field(GtkCList *List, int row, int ix, char *str) { } -//void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, int num) { -// changed int to dobule byMin +/* void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, int num) { + changed int to dobule byMin */ void gtk_set_field_num(GtkCList *List, int row, int ix, char *format, double num) { char str[32]; @@ -363,12 +363,12 @@ void gtk_update_row(GtkCList *List, int row) void gtk_redraw(void) { - int at = net_min(); // changed from 0 to net_min for TTL stuff byMin + int at = net_min(); /* changed from 0 to net_min for TTL stuff byMin */ int max = net_max(); gtk_clist_freeze(GTK_CLIST(ReportBody)); - while(GTK_CLIST(ReportBody)->rows < max -at) { // byMin + while(GTK_CLIST(ReportBody)->rows < max -at) { /* byMin */ gtk_clist_append(GTK_CLIST(ReportBody), Report_Text); } @@ -376,7 +376,7 @@ void gtk_redraw(void) gtk_clist_remove(GTK_CLIST(ReportBody), GTK_CLIST(ReportBody)->rows - 1); } - // for(at=0; at < max; at++) { // replaced byMin + /* for(at=0; at < max; at++) { replaced byMin */ for(; at < max; at++) { gtk_update_row(GTK_CLIST(ReportBody), at); } diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..5336875 --- /dev/null +++ b/hello.c @@ -0,0 +1,9 @@ +#include + +typedef int socklen_t; + +socklen_t main (int argc, char **argv) +{ + printf ("hello world. \n"); + return 2; +} diff --git a/mtr.8 b/mtr.8 index d7b297d..c1c0918 100644 --- a/mtr.8 +++ b/mtr.8 @@ -155,6 +155,16 @@ Use this option to force to display numeric IP numbers and not try to resolve the host names. +.TP +.B \-o\ fields\ order +.TP +.B \-\-order\ fields\ order +.br +Use this option to specify the fields and their order when loading mtr. +.br +Example: +-o "LSD NBAW" + .TP .B \-g .TP diff --git a/mtr.c b/mtr.c index 40ae11b..eb2abca 100644 --- a/mtr.c +++ b/mtr.c @@ -68,7 +68,7 @@ int af = DEFAULT_AF; /* begin ttl windows addByMin */ int fstTTL = 1; /* default start at first hop */ -//int maxTTL = MaxHost-1; /* max you can go is 255 hops */ +/*int maxTTL = MaxHost-1; */ /* max you can go is 255 hops */ int maxTTL = 30; /* inline with traceroute */ /* end ttl window stuff. */ @@ -330,13 +330,13 @@ int main(int argc, char **argv) } /* Now drop to user permissions */ - if (setuid(getuid())) { + if (setgid(getgid()) || setuid(getuid())) { fprintf (stderr, "mtr: Unable to drop permissions.\n"); exit(1); } /* Double check, just in case */ - if (geteuid() != getuid()) { + if ((geteuid() != getuid()) || (getegid() != getgid())) { fprintf (stderr, "mtr: Unable to drop permissions.\n"); exit(1); } diff --git a/mtr.h b/mtr.h index 5fecd2f..31ebc76 100644 --- a/mtr.h +++ b/mtr.h @@ -39,3 +39,6 @@ extern int use_dns; #define UNUSED #endif +#ifndef HAVE_SOCKLEN_T +typedef int socklen_t; +#endif diff --git a/net.c b/net.c index 327f35d..8f32aea 100644 --- a/net.c +++ b/net.c @@ -96,7 +96,7 @@ struct nethost { int avg; /* average: addByMin */ int gmean; /* geometirc mean: addByMin */ int jitter; /* current jitter, defined as t1-t0 addByMin */ -//int jbest; /* min jitter, of cause it is 0, not needed */ +/*int jbest;*/ /* min jitter, of cause it is 0, not needed */ int javg; /* avg jitter */ int jworst; /* max jitter */ int jinta; /* estimated variance,? rfc1889's "Interarrival Jitter" */ @@ -359,7 +359,7 @@ void net_process_ping(int seq, void * addr, struct timeval now) if ( addrcmp( (void *) &(host[index].addr), (void *) &unspec_addr, af ) == 0 ) { - // should be out of if as addr can change + /* should be out of if as addr can change */ addrcpy( (void *) &(host[index].addr), addrcopy, af ); display_rawhost(index, (void *) &(host[index].addr)); @@ -627,8 +627,8 @@ int net_max(void) int max; max = 0; - // replacedByMin - // for(at = 0; at < MaxHost-2; at++) { + /* replacedByMin + for(at = 0; at < MaxHost-2; at++) { */ for(at = 0; at < maxTTL-1; at++) { if ( addrcmp( (void *) &(host[at].addr), (void *) remoteaddress, af ) == 0 ) { @@ -736,12 +736,12 @@ int net_send_batch(void) n_unknown = MaxHost; /* Make sure we drop into "we should restart" */ } - if ( // success in reaching target + if ( /* success in reaching target */ ( addrcmp( (void *) &(host[batch_at].addr), (void *) remoteaddress, af ) == 0 ) || - // fail in consecuitive MAX_UNKNOWN_HOSTS (firewall?) + /* fail in consecuitive MAX_UNKNOWN_HOSTS (firewall?) */ (n_unknown > MAX_UNKNOWN_HOSTS) || - // or reach limit + /* or reach limit */ (batch_at >= maxTTL-1)) { numhosts = batch_at+1; batch_at = fstTTL - 1; diff --git a/split.c b/split.c index e49bc6b..01ceaa9 100644 --- a/split.c +++ b/split.c @@ -103,13 +103,13 @@ void split_redraw(void) name = dns_lookup(addr); if(name != NULL) { /* May be we should test name's length */ - sprintf(newLine, "%s %d %d %d %d %d %d", name, + snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d", name, net_loss(at), net_returned(at), net_xmit(at), net_best(at) /1000, net_avg(at)/1000, net_worst(at)/1000); } else { - sprintf(newLine, "%s %d %d %d %d %d %d", + snprintf(newLine, sizeof(newLine), "%s %d %d %d %d %d %d", strlongip( addr ), net_loss(at), net_returned(at), net_xmit(at),