Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 May 2009 01:38:06 +0000 (UTC)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r192069 - stable/7/lib/libutil
Message-ID:  <200905140138.n4E1c6px072838@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: des
Date: Thu May 14 01:38:06 2009
New Revision: 192069
URL: http://svn.freebsd.org/changeset/base/192069

Log:
  MFC r184633, r184635, r184683: WARNS cleanup

Modified:
  stable/7/lib/libutil/   (props changed)
  stable/7/lib/libutil/Makefile
  stable/7/lib/libutil/login_cap.c
  stable/7/lib/libutil/login_class.c
  stable/7/lib/libutil/realhostname.c

Modified: stable/7/lib/libutil/Makefile
==============================================================================
--- stable/7/lib/libutil/Makefile	Thu May 14 01:35:43 2009	(r192068)
+++ stable/7/lib/libutil/Makefile	Thu May 14 01:38:06 2009	(r192069)
@@ -16,6 +16,8 @@ SRCS=	_secure_path.c auth.c gr_util.c ex
 	stub.c trimdomain.c uucplock.c
 INCS=	libutil.h login_cap.h
 
+WARNS?=	6
+
 CFLAGS+= -DLIBC_SCCS
 
 .if ${MK_INET6_SUPPORT} != "no"

Modified: stable/7/lib/libutil/login_cap.c
==============================================================================
--- stable/7/lib/libutil/login_cap.c	Thu May 14 01:35:43 2009	(r192068)
+++ stable/7/lib/libutil/login_cap.c	Thu May 14 01:38:06 2009	(r192069)
@@ -61,6 +61,8 @@ static char * internal_string = NULL;
 static size_t internal_arraysz = 0;
 static const char ** internal_array = NULL;
 
+static char path_login_conf[] = _PATH_LOGIN_CONF;
+
 static char *
 allocstr(const char *str)
 {
@@ -215,15 +217,14 @@ login_getclassbyname(char const *name, c
 
 	if (dir && snprintf(userpath, MAXPATHLEN, "%s/%s", dir,
 			    _FILE_LOGIN_CONF) < MAXPATHLEN) {
-	    login_dbarray[i] = userpath;
 	    if (_secure_path(userpath, pwd->pw_uid, pwd->pw_gid) != -1)
-		i++;		/* only use 'secure' data */
+		login_dbarray[i++] = userpath;
 	}
 	/*
 	 * XXX: Why to add the system database if the class is `me'?
 	 */
-	if (_secure_path(_PATH_LOGIN_CONF, 0, 0) != -1)
-	    login_dbarray[i++] = _PATH_LOGIN_CONF;
+	if (_secure_path(path_login_conf, 0, 0) != -1)
+	    login_dbarray[i++] = path_login_conf;
 	login_dbarray[i] = NULL;
 
 	memset(lc, 0, sizeof(login_cap_t));

Modified: stable/7/lib/libutil/login_class.c
==============================================================================
--- stable/7/lib/libutil/login_class.c	Thu May 14 01:35:43 2009	(r192068)
+++ stable/7/lib/libutil/login_class.c	Thu May 14 01:38:06 2009	(r192069)
@@ -137,14 +137,13 @@ substvar(const char * var, const struct 
 	int	tildes = 0;
 	int	dollas = 0;
 	char	*p;
+	const char *q;
 
 	if (pwd != NULL) {
-	    /* Count the number of ~'s in var to substitute */
-	    for (p = (char *)var; (p = strchr(p, '~')) != NULL; p++)
-		++tildes;
-	    /* Count the number of $'s in var to substitute */
-	    for (p = (char *)var; (p = strchr(p, '$')) != NULL; p++)
-		++dollas;
+	    for (q = var; *q != '\0'; ++q) {
+		tildes += (*q == '~');
+		dollas += (*q == '$');
+	    }
 	}
 
 	np = malloc(strlen(var) + (dollas * nlen)

Modified: stable/7/lib/libutil/realhostname.c
==============================================================================
--- stable/7/lib/libutil/realhostname.c	Thu May 14 01:35:43 2009	(r192068)
+++ stable/7/lib/libutil/realhostname.c	Thu May 14 01:38:06 2009	(r192069)
@@ -84,6 +84,18 @@ realhostname(char *host, size_t hsize, c
 	return result;
 }
 
+/*
+ * struct sockaddr has very lax alignment requirements, since all its
+ * members are char or equivalent.  This is a problem when trying to
+ * dereference a struct sockaddr_in6 * that was passed in as a struct
+ * sockaddr *.  Although we know (or trust) that the passed-in struct was
+ * properly aligned, the compiler doesn't, and (rightly) complains.  These
+ * macros perform the cast in a way that the compiler will accept.
+ */
+#define SOCKADDR_IN6(p) ((struct sockaddr_in6 *)(void *)(p))
+#define SOCKADDR_IN(p) ((struct sockaddr_in *)(void *)(p))
+#define SOCKINET(p) ((struct sockinet *)(void *)(p))
+
 int
 realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
 {
@@ -97,10 +109,10 @@ realhostname_sa(char *host, size_t hsize
 	/* IPv4 mapped IPv6 addr consideraton, specified in rfc2373. */
 	if (addr->sa_family == AF_INET6 &&
 	    addrlen == sizeof(struct sockaddr_in6) &&
-	    IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) {
+	    IN6_IS_ADDR_V4MAPPED(&SOCKADDR_IN6(addr)->sin6_addr)) {
 		struct sockaddr_in6 *sin6;
 
-		sin6 = (struct sockaddr_in6 *)addr;
+		sin6 = SOCKADDR_IN6(addr);
 
 		memset(&lsin, 0, sizeof(lsin));
 		lsin.sin_len = sizeof(struct sockaddr_in);
@@ -143,15 +155,16 @@ realhostname_sa(char *host, size_t hsize
 			}
 			if (sa->sa_len == addrlen &&
 			    sa->sa_family == addr->sa_family) {
-				((struct sockinet *)sa)->si_port = ((struct sockinet *)addr)->si_port;
+				SOCKINET(sa)->si_port = SOCKINET(addr)->si_port;
 #ifdef INET6
 				/*
 				 * XXX: sin6_socpe_id may not been
 				 * filled by DNS
 				 */
 				if (sa->sa_family == AF_INET6 &&
-				    ((struct sockaddr_in6 *)sa)->sin6_scope_id == 0)
-					((struct sockaddr_in6 *)sa)->sin6_scope_id = ((struct sockaddr_in6 *)addr)->sin6_scope_id;
+				    SOCKADDR_IN6(sa)->sin6_scope_id == 0)
+					SOCKADDR_IN6(sa)->sin6_scope_id =
+					    SOCKADDR_IN6(addr)->sin6_scope_id;
 #endif
 				if (!memcmp(sa, addr, sa->sa_len)) {
 					result = HOSTNAME_FOUND;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905140138.n4E1c6px072838>