Jap-Peter Seifert) and use strlcat instead of strncat.
# 7. Functions, global variables
AC_FUNC_STRERROR_R
-AC_CHECK_FUNCS(strtoul strtoll)
+AC_CHECK_FUNCS(strtoul strtoll strlcpy)
if test x"$enable_unicode" = xyes; then
AC_CHECK_FUNCS(iswascii)
truncated = SOCK_get_string(sock, new_format ? msgbuffer : msgbuf, new_format ? sizeof(msgbuffer) : buflen);
if (new_format)
{
- size_t msgl;
+ size_t dstlen = 0;
msgbuf[0] = '\0';
for (;msgbuffer[0];)
{
mylog("%s: 'E' - %s\n", comment, msgbuffer);
qlog("ERROR from backend during %s: '%s'\n", comment, msgbuffer);
- msgl = strlen(msgbuffer + 1);
switch (msgbuffer[0])
{
case 'S':
- if (buflen > 0)
- {
- strncat(msgbuf, msgbuffer + 1, buflen);
- buflen -= msgl;
- }
- if (buflen > 0)
- {
- strncat(msgbuf, ": ", buflen);
- buflen -= 2;
- }
+ strlcat(msgbuf, msgbuffer + 1, buflen);
+ dstlen = strlcat(msgbuf, ": ", buflen);
break;
case 'M':
case 'D':
- if (buflen > 0)
- {
- if (hasmsg)
- {
- strcat(msgbuf, "\n");
- buflen--;
- }
- if (buflen > 0)
- {
- strncat(msgbuf, msgbuffer + 1, buflen);
- buflen -= msgl;
- }
- }
+ if (hasmsg)
+ strlcat(msgbuf, "\n", buflen);
+ dstlen = strlcat(msgbuf, msgbuffer + 1, buflen);
if (truncated)
msg_truncated = truncated;
hasmsg = TRUE;
strncpy_null(sqlstate, msgbuffer + 1, 8);
break;
}
- if (buflen < 0)
- buflen = 0;
while (truncated)
truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
if (new_format)
{
- size_t msgl;
+ size_t dstlen = 0;
msgbuf[0] = '\0';
for (;;)
mylog("%s: 'N' - %s\n", comment, msgbuffer);
qlog("NOTICE from backend during %s: '%s'\n", comment, msgbuffer);
- msgl = strlen(msgbuffer + 1);
switch (msgbuffer[0])
{
case 'S':
- if (buflen > 0)
- {
- strncat(msgbuf, msgbuffer + 1, buflen);
- buflen -= msgl;
- }
- if (buflen > 0)
- {
- strncat(msgbuf, ": ", buflen);
- buflen -= 2;
- }
+ strlcat(msgbuf, msgbuffer + 1, buflen);
+ dstlen = strlcat(msgbuf, ": ", buflen);
break;
case 'M':
case 'D':
- if (buflen > 0)
- {
- if (hasmsg)
- {
- strcat(msgbuf, "\n");
- buflen--;
- }
- if (buflen > 0)
- {
- strncat(msgbuf, msgbuffer + 1, buflen);
- buflen -= msgl;
- }
- }
- else
- msg_truncated = TRUE;
+ if (hasmsg)
+ strlcat(msgbuf, "\n", buflen);
+ dstlen = strlcat(msgbuf, msgbuffer + 1, buflen);
if (truncated)
msg_truncated = truncated;
hasmsg = TRUE;
strncpy_null(sqlstate, msgbuffer + 1, 8);
break;
}
- if (buflen < 0)
+ if (dstlen >= buflen)
msg_truncated = TRUE;
while (truncated)
truncated = SOCK_get_string(sock, msgbuffer, sizeof(msgbuffer));
" where tc.oid = " FORMAT_UINT4
, reloid);
- strncat(tables_query,
+ strlcat(tables_query,
" AND tc.oid = i.indrelid"
" AND n.oid = tc.relnamespace"
" AND i.indisprimary = 't'"
snprintf(tbqry, tsize,
" where tc.oid = " FORMAT_UINT4, reloid);
- strncat(tables_query,
+ strlcat(tables_query,
" AND tc.oid = i.indrelid"
" AND i.indisprimary = 't'"
" AND ia.attrelid = i.indexrelid"
va_end(arglist);
return len;
}
+
+#ifndef HAVE_STRLCAT
+size_t
+strlcat(char *dst, const char *src, size_t size)
+{
+ size_t ttllen;
+ char *pd = dst;
+ const char *ps= src;
+
+ for (ttllen = 0; ttllen < size; ttllen++, pd++)
+ {
+ if (0 == *pd)
+ break;
+ }
+ if (ttllen >= size - 1)
+ return ttllen + strlen(src);
+ for (; ttllen < size - 1; ttllen++, pd++, ps++)
+ {
+ if (0 == (*pd = *ps))
+ return ttllen;
+ }
+ *pd = 0;
+ for (; *ps; ttllen++, ps++)
+ ;
+ return ttllen;
+}
+#endif /* HAVE_STRLCAT */
void remove_newlines(char *string);
char *strncpy_null(char *dst, const char *src, ssize_t len);
+#ifndef HAVE_STRLCPY
+size_t strlcat(char *, const char *, size_t);
+#endif /* HAVE_STRLCPY */
char *my_trim(char *string);
char *make_string(const char *s, ssize_t len, char *buf, size_t bufsize);
char *make_lstring_ifneeded(ConnectionClass *, const char *s, ssize_t len, BOOL);
*
* Comments: See "notice.txt" for copyright and license information.
*
- * $Id: psqlodbc.h,v 1.133 2010/01/17 13:10:41 hinoue Exp $
+ * $Id: psqlodbc.h,v 1.134 2010/01/24 07:56:13 hinoue Exp $
*
*/
#define FALSE (BOOL)0
#endif /* FALSE */
#else
-#if (_MSC_VER >= 1400) && !defined(_WIN64)
-#define snprintf sprintf_s
-#define strncat(d, s, l) strcat_s(d, l, s)
-#else
#define snprintf _snprintf
-#endif
#ifndef strdup
#define strdup _strdup
#endif /* strdup */
CC_cursor_count(conn) <= 1)
{
mylog("QResult: END transaction on conn=%p\n", conn);
- strncat(buf, ";commit", sizeof(buf));
+ strlcat(buf, ";commit", sizeof(buf));
flag |= END_WITH_COMMIT;
QR_set_cursor(self, NULL);
}
#define POSTGRESDRIVERVERSION "08.04.0201"
#define POSTGRES_RESOURCE_VERSION "08.04.0201\0"
#define PG_DRVFILE_VERSION 8,4,02,01
-#define PG_BUILD_VERSION "201001230001"
+#define PG_BUILD_VERSION "201001240001"
#endif