svn commit: r351964 - stable/12/sbin/ping6

Alan Somers asomers at FreeBSD.org
Fri Sep 6 20:16:09 UTC 2019


Author: asomers
Date: Fri Sep  6 20:16:08 2019
New Revision: 351964
URL: https://svnweb.freebsd.org/changeset/base/351964

Log:
  MFC r350858-r350859, r350987, r351170
  
  r350858:
  ping6: Add missing static keyword for a global variable
  
  This fixes -Wmissing-variable-declarations error when compiled with
  WARNS=6.
  
  Submitted by:	Ján Sučan <sucanjan at gmail.com>
  Sponsored by:	Google, inc. (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21214
  
  r350859:
  ping6: Remove unnecessary level of indirection from dnsdecode() parameter
  
  The `sp' pointer doesn't need to be modified in the caller of
  dnsdecode().
  
  This fixes -Wcast-qual error (`must have all intermediate pointers
  const qualified to be safe') when compiled with WARNS=6.
  
  Submitted by:	Ján Sučan <sucanjan at gmail.com>
  Sponsored by:	Google, inc. (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21215
  
  r350987:
  ping6: Fix data type of a variable for a packet sequence number
  
  Submitted by:   Ján Sučan <sucanjan at gmail.com>
  Sponsored by:   Google, inc. (Google Summer of Code 2019)
  Differential Revision:  https://reviews.freebsd.org/D21218
  
  r351170:
  ping6: Fix dnsdecode() bug introduced by r350859
  
  Revision 350859 removed level of indirection that was needed for setting the
  caller's `cp' pointer. dnsdecode() uses return value to indicate error or
  success. It returns pointer to a buffer holding a decompressed DNS name or
  NULL. The caller uses that value only to find out the result, not for accessing
  the buffer.
  
  We use the return value to propagate the new value of `cp' pointer to
  the caller instead of using an output argument.
  
  Submitted by:	Ján Sučan <sucanjan at gmail.com>
  MFC-With:	350859
  Sponsored by:	Google, Inc (Google Summer of Code 2019)
  Differential Revision:	https://reviews.freebsd.org/D21266

Modified:
  stable/12/sbin/ping6/ping6.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/ping6/ping6.c
==============================================================================
--- stable/12/sbin/ping6/ping6.c	Fri Sep  6 19:50:45 2019	(r351963)
+++ stable/12/sbin/ping6/ping6.c	Fri Sep  6 20:16:08 2019	(r351964)
@@ -198,7 +198,7 @@ struct tv32 {
 #define F_DONTFRAG	0x1000000
 #define F_NOUSERDATA	(F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES)
 #define	F_WAITTIME	0x2000000
-u_int options;
+static u_int options;
 
 #define IN6LEN		sizeof(struct in6_addr)
 #define SA6LEN		sizeof(struct sockaddr_in6)
@@ -279,7 +279,7 @@ static void	 pr_suptypes(struct icmp6_nodeinfo *, size
 static void	 pr_nodeaddr(struct icmp6_nodeinfo *, int);
 static int	 myechoreply(const struct icmp6_hdr *);
 static int	 mynireply(const struct icmp6_nodeinfo *);
-static char *dnsdecode(const u_char **, const u_char *, const u_char *,
+static const char *dnsdecode(const u_char *, const u_char *, const u_char *,
     char *, size_t);
 static void	 pr_pack(u_char *, int, struct msghdr *);
 static void	 pr_exthdrs(struct msghdr *);
@@ -1304,7 +1304,7 @@ pinger(void)
 	struct iovec iov[2];
 	int i, cc;
 	struct icmp6_nodeinfo *nip;
-	int seq;
+	uint16_t seq;
 
 	if (npackets && ntransmitted >= npackets)
 		return(-1);	/* no more transmission */
@@ -1430,10 +1430,26 @@ mynireply(const struct icmp6_nodeinfo *nip)
 		return 0;
 }
 
-static char *
-dnsdecode(const u_char **sp, const u_char *ep, const u_char *base, char *buf,
+/*
+ * Decode a name from a DNS message.
+ *
+ * Format of the message is described in RFC 1035 subsection 4.1.4.
+ *
+ * Arguments:
+ *   sp     - Pointer to a DNS pointer octet or to the first octet of a label
+ *            in the message.
+ *   ep     - Pointer to the end of the message (one step past the last octet).
+ *   base   - Pointer to the beginning of the message.
+ *   buf    - Buffer into which the decoded name will be saved.
+ *   bufsiz - Size of the buffer 'buf'.
+ *
+ * Return value:
+ *   Pointer to an octet immediately following the ending zero octet
+ *   of the decoded label, or NULL if an error occured.
+ */
+static const char *
+dnsdecode(const u_char *sp, const u_char *ep, const u_char *base, char *buf,
 	size_t bufsiz)
-	/*base for compressed name*/
 {
 	int i;
 	const u_char *cp;
@@ -1441,14 +1457,14 @@ dnsdecode(const u_char **sp, const u_char *ep, const u
 	const u_char *comp;
 	int l;
 
-	cp = *sp;
+	cp = sp;
 	*buf = '\0';
 
 	if (cp >= ep)
 		return NULL;
 	while (cp < ep) {
 		i = *cp;
-		if (i == 0 || cp != *sp) {
+		if (i == 0 || cp != sp) {
 			if (strlcat((char *)buf, ".", bufsiz) >= bufsiz)
 				return NULL;	/*result overrun*/
 		}
@@ -1462,7 +1478,7 @@ dnsdecode(const u_char **sp, const u_char *ep, const u
 				return NULL;
 
 			comp = base + (i & 0x3f);
-			if (dnsdecode(&comp, cp, base, cresult,
+			if (dnsdecode(comp, cp, base, cresult,
 			    sizeof(cresult)) == NULL)
 				return NULL;
 			if (strlcat(buf, cresult, bufsiz) >= bufsiz)
@@ -1486,8 +1502,7 @@ dnsdecode(const u_char **sp, const u_char *ep, const u
 	if (i != 0)
 		return NULL;	/*not terminated*/
 	cp++;
-	*sp = cp;
-	return buf;
+	return cp;
 }
 
 /*
@@ -1507,7 +1522,8 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr)
 	int hoplim;
 	struct sockaddr *from;
 	int fromlen;
-	u_char *cp = NULL, *dp, *end = buf + cc;
+	const u_char *cp = NULL;
+	u_char *dp, *end = buf + cc;
 	struct in6_pktinfo *pktinfo = NULL;
 	struct timeval tv, tp;
 	struct tv32 *tpp;
@@ -1679,9 +1695,10 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr)
 			} else {
 				i = 0;
 				while (cp < end) {
-					if (dnsdecode((const u_char **)&cp, end,
+					cp = dnsdecode((const u_char *)cp, end,
 					    (const u_char *)(ni + 1), dnsname,
-					    sizeof(dnsname)) == NULL) {
+					    sizeof(dnsname));
+					if (cp == NULL) {
 						printf("???");
 						break;
 					}
@@ -2461,8 +2478,9 @@ pr_icmph(struct icmp6_hdr *icp, u_char *end)
 				}
 				printf(", subject=%s", niqcode[ni->ni_code]);
 				cp = (const u_char *)(ni + 1);
-				if (dnsdecode(&cp, end, NULL, dnsname,
-				    sizeof(dnsname)) != NULL)
+				cp = dnsdecode(cp, end, NULL, dnsname,
+				    sizeof(dnsname));
+				if (cp != NULL)
 					printf("(%s)", dnsname);
 				else
 					printf("(invalid)");


More information about the svn-src-all mailing list