ci = &conn->connInfo;
- make_string(szDSN, cbDSN, ci->dsn);
+ make_string(szDSN, cbDSN, ci->dsn, sizeof(ci->dsn));
/* get the values for the DSN from the registry */
memcpy(&ci->drivers, &globals, sizeof(globals));
* override values from DSN info with UID and authStr(pwd) This only
* occurs if the values are actually there.
*/
- make_string(szUID, cbUID, ci->username);
- make_string(szAuthStr, cbAuthStr, ci->password);
+ make_string(szUID, cbUID, ci->username, sizeof(ci->username));
+ make_string(szAuthStr, cbAuthStr, ci->password, sizeof(ci->password));
/* fill in any defaults */
getDSNdefaults(ci);
RETCODE dialog_result;
#endif
RETCODE result;
- char connStrIn[MAX_CONNECT_STRING];
+ char *connStrIn;
char connStrOut[MAX_CONNECT_STRING];
int retval;
char salt[5];
return SQL_INVALID_HANDLE;
}
- make_string(szConnStrIn, cbConnStrIn, connStrIn);
+ connStrIn = make_string(szConnStrIn, cbConnStrIn, NULL, 0);
#ifdef FORCE_PASSWORD_DISPLAY
mylog("**** PGAPI_DriverConnect: fDriverCompletion=%d, connStrIn='%s'\n", fDriverCompletion, connStrIn);
#endif /* FORCE_PASSWORD_DISPLAY */
+ if (connStrIn)
+ free(connStrIn);
+
mylog("PGAPI_DriverConnect: returning %d\n", result);
return result;
}
if (!szSqlStr[0])
self->statement = strdup("");
else
- self->statement = make_string(szSqlStr, cbSqlStr, NULL);
+ self->statement = make_string(szSqlStr, cbSqlStr, NULL, 0);
if (!self->statement)
{
SC_set_error(self, STMT_NO_MEMORY_ERROR, "No memory available to store statement");
* keep a copy of the un-parametrized statement, in case they try to
* execute this statement again
*/
- stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
+ stmt->statement = make_string(szSqlStr, cbSqlStr, NULL, 0);
if (!stmt->statement)
{
SC_set_error(stmt, STMT_NO_MEMORY_ERROR, "No memory available to store statement");
mylog("%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn);
- ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL);
+ ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL, 0);
if (!ptr)
{
CC_set_error(conn, CONN_NO_MEMORY_ERROR, "No memory available to store native sql string");
show_views = FALSE;
/* make_string mallocs memory */
- tableType = make_string(szTableType, cbTableType, NULL);
+ tableType = make_string(szTableType, cbTableType, NULL, 0);
if (tableType)
{
strcpy(table_types, tableType);
* only use the table name... the owner should be redundant, and we
* never use qualifiers.
*/
- table_name = make_string(szTableName, cbTableName, NULL);
+ table_name = make_string(szTableName, cbTableName, NULL, 0);
if (!table_name)
{
SC_set_error(stmt, STMT_INTERNAL_ERROR, "No table name passed to PGAPI_Statistics.");
char tables_query[INFO_INQUIRY_LEN];
char attname[MAX_INFO_STRING];
SDWORD attname_len;
- char pktab[TABLE_NAME_STORAGE_LEN + 1], pkscm[TABLE_NAME_STORAGE_LEN + 1];
+ char *pktab;
+ char pkscm[TABLE_NAME_STORAGE_LEN + 1];
Int2 result_cols;
int qno,
qstart,
internal_asis_type = INTERNAL_ASIS_TYPE;
#endif /* UNICODE_SUPPORT */
- pktab[0] = '\0';
- make_string(szTableName, cbTableName, pktab);
- if (pktab[0] == '\0')
+ pktab = make_string(szTableName, cbTableName, NULL, 0);
+ if (pktab == NULL || pktab[0] == '\0')
{
SC_set_error(stmt, STMT_INTERNAL_ERROR, "No Table specified to PGAPI_PrimaryKeys.");
goto cleanup;
ret = SQL_SUCCESS;
cleanup:
+ if (pktab)
+ free(pktab);
+
/*
* also, things need to think that this statement is finished so the
* results can be retrieved.
char trig_args[1024];
char upd_rule[TABLE_NAME_STORAGE_LEN],
del_rule[TABLE_NAME_STORAGE_LEN];
- char pk_table_needed[TABLE_NAME_STORAGE_LEN + 1];
-char fk_table_fetched[TABLE_NAME_STORAGE_LEN + 1];
- char fk_table_needed[TABLE_NAME_STORAGE_LEN + 1];
-char pk_table_fetched[TABLE_NAME_STORAGE_LEN + 1];
+ char *pk_table_needed;
+ char fk_table_fetched[TABLE_NAME_STORAGE_LEN + 1];
+ char *fk_table_needed;
+ char pk_table_fetched[TABLE_NAME_STORAGE_LEN + 1];
char schema_needed[SCHEMA_NAME_STORAGE_LEN + 1];
-char schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
+ char schema_fetched[SCHEMA_NAME_STORAGE_LEN + 1];
char *pkey_ptr,
*pkey_text,
*fkey_ptr,
tbl_stmt = (StatementClass *) htbl_stmt;
- pk_table_needed[0] = '\0';
- fk_table_needed[0] = '\0';
schema_needed[0] = '\0';
schema_fetched[0] = '\0';
- make_string(szPkTableName, cbPkTableName, pk_table_needed);
- make_string(szFkTableName, cbFkTableName, fk_table_needed);
+ pk_table_needed = make_string(szPkTableName, cbPkTableName, NULL, 0);
+ fk_table_needed = make_string(szFkTableName, cbFkTableName, NULL, 0);
conn = SC_get_conn(stmt);
#ifdef UNICODE_SUPPORT
* Case #2 -- Get the foreign keys in the specified table (fktab) that
* refer to the primary keys of other table(s).
*/
- if (fk_table_needed[0] != '\0')
+ if (fk_table_needed && fk_table_needed[0] != '\0')
{
mylog("%s: entering Foreign Key Case #2", func);
if (conn->schema_support)
mylog("Foreign Key Case#2: trig_nargs = %d, num_keys = %d\n", trig_nargs, num_keys);
/* If there is a pk table specified, then check it. */
- if (pk_table_needed[0] != '\0')
+ if (pk_table_needed && pk_table_needed[0] != '\0')
{
/* If it doesn't match, then continue */
if (strcmp(pk_table_fetched, pk_table_needed))
ret = SQL_SUCCESS;
cleanup:
+ if (fk_table_needed)
+ free(fk_table_needed);
+ if (pk_table_needed)
+ free(pk_table_needed);
+
+
/*
* also, things need to think that this statement is finished so the
* results can be retrieved.
/*------
* Create a null terminated string (handling the SQL_NTS thing):
* 1. If buf is supplied, place the string in there
- * (assumes enough space) and return buf.
+ * (at most bufsize-1 bytes) and return buf.
* 2. If buf is not supplied, malloc space and return this string
+ * (buflen is ignored in this case)
*------
*/
char *
-make_string(const char *s, int len, char *buf)
+make_string(const char *s, int len, char *buf, size_t bufsize)
{
- int length;
+ unsigned int length;
char *str;
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0)))
if (buf)
{
+ if (length >= bufsize)
+ length = bufsize - 1;
strncpy_null(buf, s, length + 1);
return buf;
}
void remove_newlines(char *string);
char *strncpy_null(char *dst, const char *src, int len);
char *trim(char *string);
-char *make_string(const char *s, int len, char *buf);
+char *make_string(const char *s, int len, char *buf, size_t bufsize);
char *make_lstring_ifneeded(ConnectionClass *, const char *s, int len, BOOL);
char *my_strcat(char *buf, const char *fmt, const char *s, int len);
char *schema_strcat(char *buf, const char *fmt, const char *s, int len,