Skip to content

Commit 0be5b9e

Browse files
committed
Prevent modifying of getenv result
1 parent 008eb14 commit 0be5b9e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ int fpm_sockets_init_main() /* {{{ */
348348
unsigned i, lq_len;
349349
struct fpm_worker_pool_s *wp;
350350
char sockname[32];
351+
char sockpath[256];
351352
char *inherited;
352353
struct listening_socket_s *ls;
353354

@@ -363,7 +364,9 @@ int fpm_sockets_init_main() /* {{{ */
363364
sprintf(sockname, "FPM_SOCKETS_%d", i);
364365
}
365366
inherited = getenv(sockname);
366-
if (!inherited) break;
367+
if (!inherited) {
368+
break;
369+
}
367370

368371
while (inherited && *inherited) {
369372
char *comma = strchr(inherited, ',');
@@ -376,11 +379,17 @@ int fpm_sockets_init_main() /* {{{ */
376379

377380
eq = strchr(inherited, '=');
378381
if (eq) {
379-
*eq = '\0';
382+
int sockpath_len = eq - inherited;
383+
if (sockpath_len > 255) {
384+
/* this should never happen as UDS limit is lower */
385+
sockpath_len = 255;
386+
}
387+
memcpy(sockpath, inherited, sockpath_len);
388+
sockpath[sockpath_len] = '\0';
380389
fd_no = atoi(eq + 1);
381-
type = fpm_sockets_domain_from_address(inherited);
382-
zlog(ZLOG_NOTICE, "using inherited socket fd=%d, \"%s\"", fd_no, inherited);
383-
fpm_sockets_hash_op(fd_no, 0, inherited, type, FPM_STORE_SOCKET);
390+
type = fpm_sockets_domain_from_address(sockpath);
391+
zlog(ZLOG_NOTICE, "using inherited socket fd=%d, \"%s\"", fd_no, sockpath);
392+
fpm_sockets_hash_op(fd_no, 0, sockpath, type, FPM_STORE_SOCKET);
384393
}
385394

386395
if (comma) {

0 commit comments

Comments
 (0)