Skip to content

Commit a333d15

Browse files
author
hackorum
committed
Apply ecgp_sqlstate-v2.diff
1 parent 1d1d7b0 commit a333d15

19 files changed

Lines changed: 27 additions & 3 deletions

doc/src/sgml/ecpg.sgml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,6 +5050,7 @@ struct
50505050
long sqlerrd[6];
50515051
char sqlwarn[8];
50525052
char sqlstate[5];
5053+
char sqlstatepad;
50535054
} sqlca;
50545055
</programlisting>
50555056
(In a multithreaded program, every thread automatically gets its
@@ -5199,6 +5200,11 @@ sqlstate: 42P01
51995200
throughout all applications. For further information see
52005201
<xref linkend="errcodes-appendix"/>.
52015202
</para>
5203+
<para>
5204+
<literal>sqlca.sqlstate</literal> field is a non-terminated character
5205+
array, in order to guard against accidental uses as a C string it is
5206+
followed by a padding nul character.
5207+
</para>
52025208

52035209
<para>
52045210
<literal>SQLCODE</literal>, the deprecated error code scheme, is a

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static struct sqlca_t sqlca_init =
5252
},
5353
{
5454
'0', '0', '0', '0', '0'
55-
}
55+
},
56+
'\0'
5657
};
5758

5859
static pthread_key_t sqlca_key;
@@ -276,8 +277,8 @@ ecpg_log(const char *format, ...)
276277
/* dump out internal sqlca variables */
277278
if (ecpg_internal_regression_mode && sqlca != NULL)
278279
{
279-
fprintf(debugstream, "[NO_PID]: sqlca: code: %ld, state: %s\n",
280-
sqlca->sqlcode, sqlca->sqlstate);
280+
fprintf(debugstream, "[NO_PID]: sqlca: code: %ld, state: %.*s\n",
281+
sqlca->sqlcode, (int) sizeof(sqlca->sqlstate), sqlca->sqlstate);
281282
}
282283

283284
fflush(debugstream);

src/interfaces/ecpg/include/sqlca.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct sqlca_t
5151
/* 7: empty */
5252

5353
char sqlstate[5];
54+
char sqlstatepad; /* nul terminator for sqlstate */
5455
};
5556

5657
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct sqlca_t
6868
/* 7: empty */
6969

7070
char sqlstate[5];
71+
char sqlstatepad; /* nul terminator for sqlstate */
7172
};
7273

7374
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/preproc-init.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct sqlca_t
6262
/* 7: empty */
6363

6464
char sqlstate[5];
65+
char sqlstatepad; /* nul terminator for sqlstate */
6566
};
6667

6768
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/sql-array.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct sqlca_t
7575
/* 7: empty */
7676

7777
char sqlstate[5];
78+
char sqlstatepad; /* nul terminator for sqlstate */
7879
};
7980

8081
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/sql-code100.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct sqlca_t
6262
/* 7: empty */
6363

6464
char sqlstate[5];
65+
char sqlstatepad; /* nul terminator for sqlstate */
6566
};
6667

6768
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/sql-copystdout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct sqlca_t
6464
/* 7: empty */
6565

6666
char sqlstate[5];
67+
char sqlstatepad; /* nul terminator for sqlstate */
6768
};
6869

6970
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/sql-declare.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct sqlca_t
7070
/* 7: empty */
7171

7272
char sqlstate[5];
73+
char sqlstatepad; /* nul terminator for sqlstate */
7374
};
7475

7576
struct sqlca_t *ECPGget_sqlca(void);

src/interfaces/ecpg/test/expected/sql-define.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct sqlca_t
7777
/* 7: empty */
7878

7979
char sqlstate[5];
80+
char sqlstatepad; /* nul terminator for sqlstate */
8081
};
8182

8283
struct sqlca_t *ECPGget_sqlca(void);

0 commit comments

Comments
 (0)