Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Rebuilding from CVS on Snow Leopard



At 22:50 -0700 09/09/27, Bart Schaefer wrote:
>gcc -c -I. -DHAVE_CONFIG_H -DMODULE -Wall -Wmissing-prototypes -O2 - fno-common -o socket..o socket.c
>socket.c: In function 'bin_zsocket':
>socket.c:106: warning: call to __builtin___strncpy_chk will always overflow destination buffer >socket.c:235: warning: call to __builtin___strncpy_chk will always overflow destination buffer

MacOSX (and many BSD's as well?) does not define UNIX_PATH_MAX,
and struct sockaddr_un is defined in sys/un.h as

struct  sockaddr_un {
unsigned char sun_len; /* sockaddr len including null */
        sa_family_t     sun_family;     /* [XSI] AF_UNIX */
        char            sun_path[104];  /* [XSI] path name (gag) */
};

so we can't define UNIX_PATH_MAX to 108.

I think it would be better to use sizeof(soun.sun_path) in place
of UNIX_PATH_MAX. Or use sizeof(soun.sun_path)-1 so that sun_path
is always null terminated.


Index: Src/Modules/socket.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/socket.c,v
retrieving revision 1.13
diff -u -r1.13 socket.c
--- Src/Modules/socket.c	22 Sep 2009 16:04:15 -0000	1.13
+++ Src/Modules/socket.c	29 Sep 2009 10:11:35 -0000
@@ -33,10 +33,6 @@
 #include <sys/socket.h>
 #include <sys/un.h>

-#ifndef UNIX_PATH_MAX
-# define UNIX_PATH_MAX 108
-#endif
-
 /*
  * We need to include the zsh headers later to avoid clashes with
  * the definitions on some systems, however we need the configuration
@@ -103,7 +99,7 @@
 	}

 	soun.sun_family = AF_UNIX;
-	strncpy(soun.sun_path, localfn, UNIX_PATH_MAX);
+	strncpy(soun.sun_path, localfn, sizeof(soun.sun_path)-1);

 	if (bind(sfd, (struct sockaddr *)&soun, sizeof(struct sockaddr_un)))
 	{
@@ -232,7 +228,7 @@
 	}

 	soun.sun_family = AF_UNIX;
-	strncpy(soun.sun_path, args[0], UNIX_PATH_MAX);
+	strncpy(soun.sun_path, args[0], sizeof(soun.sun_path)-1);
 	
if ((err = connect(sfd, (struct sockaddr *)&soun, sizeof(struct sockaddr_un)))) {
 	    zwarnnam(nam, "connection failed: %e", errno);



Messages sorted by: Reverse Date, Date, Thread, Author