Skip to content

Commit 1f41da6

Browse files
orlsmichael-grunder
authored andcommitted
Fix "No such file or directory" when connecting to ports >= 32768 (phpredis#1602)
* Fix `connect` for port numbers >=32768: Since 5.0.0, using a high enough port number gives a "No such file or directory" error, because type casts treat high ports as -ve which awkwardly triggers the unix-socket-path behaviour. * clean up guard condition
1 parent 4ab69b1 commit 1f41da6

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ typedef struct fold_item {
248248
typedef struct {
249249
php_stream *stream;
250250
zend_string *host;
251-
short port;
251+
unsigned short port;
252252
zend_string *auth;
253253
double timeout;
254254
double read_timeout;

redis.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,10 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
10051005
port = 6379;
10061006
}
10071007

1008+
if (port < 0) {
1009+
port = 0;
1010+
}
1011+
10081012
redis = PHPREDIS_GET_OBJECT(redis_object, object);
10091013
/* if there is a redis sock already we have to remove it */
10101014
if (redis->sock) {

0 commit comments

Comments
 (0)