Skip to content

Commit b38423c

Browse files
author
Ard Biesheuvel
committed
MFH: Fixed bug #28569 (connection id is not thread safe)
1 parent f620692 commit b38423c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

ext/informix/ifx.ec

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
#include <winsock.h>
5555
#endif
5656

57+
#ifdef ZTS
58+
#define IFX_THRD_ID tsrm_thread_id()
59+
#else
60+
#define IFX_THRD_ID 0
61+
#endif
62+
5763
#if HAVE_SYS_TYPES_H
5864
#include <sys/types.h>
5965
#endif
@@ -542,7 +548,7 @@ EXEC SQL END DECLARE SECTION;
542548
/* create the link */
543549
ifx = (char *) malloc(sizeof(IFX));
544550
IFXG(connectionid)++;
545-
sprintf(ifx, "%s%x", SAFE_STRING(user), IFXG(connectionid));
551+
sprintf(ifx, "%s%x_%x", SAFE_STRING(user), IFX_THRD_ID,IFXG(connectionid));
546552

547553
EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;
548554

@@ -645,7 +651,7 @@ EXEC SQL END DECLARE SECTION;
645651

646652
ifx = (char *) emalloc(sizeof(IFX));
647653
IFXG(connectionid)++;
648-
sprintf(ifx, "connec%x", IFXG(connectionid));
654+
sprintf(ifx, "connec%x_%x", IFX_THRD_ID, IFXG(connectionid));
649655

650656
EXEC SQL CONNECT TO :host AS :ifx USER :user USING :passwd WITH CONCURRENT TRANSACTION;
651657

@@ -818,10 +824,10 @@ EXEC SQL END DECLARE SECTION;
818824
statement = Z_STRVAL_PP(query);
819825

820826
IFXG(cursorid)++;
821-
sprintf(statemid, "statem%x", IFXG(cursorid));
822-
sprintf(cursorid, "cursor%x", IFXG(cursorid));
823-
sprintf(descrpid, "descrp%x", IFXG(cursorid));
824-
sprintf(i_descrpid, "i_descrp%x", IFXG(cursorid));
827+
sprintf(statemid, "statem%x_%x", IFX_THRD_ID, IFXG(cursorid));
828+
sprintf(cursorid, "cursor%x_%x", IFX_THRD_ID, IFXG(cursorid));
829+
sprintf(descrpid, "descrp%x_%x", IFX_THRD_ID, IFXG(cursorid));
830+
sprintf(i_descrpid, "i_descrp%x_%x", IFX_THRD_ID,IFXG(cursorid));
825831

826832
EXEC SQL set connection :ifx;
827833
PHP_IFX_CHECK_CONNECTION(ifx);
@@ -1242,10 +1248,10 @@ EXEC SQL END DECLARE SECTION;
12421248
statement = Z_STRVAL_PP(query);
12431249

12441250
IFXG(cursorid)++;
1245-
sprintf(statemid, "statem%x", IFXG(cursorid));
1246-
sprintf(cursorid, "cursor%x", IFXG(cursorid));
1247-
sprintf(descrpid, "descrp%x", IFXG(cursorid));
1248-
sprintf(i_descrpid, "i_descrp%x", IFXG(cursorid));
1251+
sprintf(statemid, "statem%x_%x", IFX_THRD_ID, IFXG(cursorid));
1252+
sprintf(cursorid, "cursor%x_%x", IFX_THRD_ID, IFXG(cursorid));
1253+
sprintf(descrpid, "descrp%x_%x", IFX_THRD_ID, IFXG(cursorid));
1254+
sprintf(i_descrpid, "i_descrp%x_%x", IFX_THRD_ID,IFXG(cursorid));
12491255

12501256
EXEC SQL set connection :ifx;
12511257
PHP_IFX_CHECK_CONNECTION(ifx);

0 commit comments

Comments
 (0)