Created
March 19, 2015 08:09
-
-
Save bow-fujita/a338e35b95605ad63147 to your computer and use it in GitHub Desktop.
Patch for TokyoTyrant to fix UNIX socket issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -urN tokyotyrant-1.1.41.orig/ttutil.c tokyotyrant-1.1.41/ttutil.c | |
--- tokyotyrant-1.1.41.orig/ttutil.c 2010-08-04 23:24:33.000000000 -0700 | |
+++ tokyotyrant-1.1.41/ttutil.c 2015-03-19 01:04:27.000000000 -0700 | |
@@ -24,7 +24,6 @@ | |
*************************************************************************************************/ | |
-#define SOCKPATHBUFSIZ 108 // size of a socket path buffer | |
#define SOCKRCVTIMEO 0.25 // timeout of the recv call of socket | |
#define SOCKSNDTIMEO 0.25 // timeout of the send call of socket | |
#define SOCKCNCTTIMEO 5.0 // timeout of the connect call of socket | |
@@ -127,7 +126,7 @@ | |
struct sockaddr_un saun; | |
memset(&saun, 0, sizeof(saun)); | |
saun.sun_family = AF_UNIX; | |
- snprintf(saun.sun_path, SOCKPATHBUFSIZ, "%s", path); | |
+ strncpy(saun.sun_path, path, sizeof(saun.sun_path)-1); | |
int fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
if(fd == -1) return -1; | |
int optint = 1; | |
@@ -187,7 +186,7 @@ | |
struct sockaddr_un saun; | |
memset(&saun, 0, sizeof(saun)); | |
saun.sun_family = AF_UNIX; | |
- snprintf(saun.sun_path, SOCKPATHBUFSIZ, "%s", path); | |
+ strncpy(saun.sun_path, path, sizeof(saun.sun_path)-1); | |
int fd = socket(PF_UNIX, SOCK_STREAM, 0); | |
if(fd == -1) return -1; | |
if(bind(fd, (struct sockaddr *)&saun, sizeof(saun)) != 0 || |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Starting TokyoTyrant with the following command doesn't work on Mac OS X:
It's because of difference between
SOCKPATHBUFSIZ
andsizeof(sockaddr_un.sun_path)
.struct sockaddr_un
is defined in/usr/include/sys/un.h
on Mac OS X as follow:So
SOCKPATHBUFSIZ
(=108) is greater than actual size ofsockaddr_un.sun_path
and it may cause buffer overflow.