Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63d7df4

Browse files
committed
Small patch which fixes the ODBC driver so it doesn't segfault if:
You have CommLog and Debug enabledYou encounter in error in any operation (SQLConnect/SQLExec).Previously, the extra logging didn't check for NULL pointerswhen trying to print some of the strings- the socket errormessage could frequently be NULL by design (if there was no socketerror)and Solaris does not handle NULLS passed to things like printf("%s\n",string);gracefully.This basically duplicates the functionality found in Linux where passinga null pointerto printf prints "(NULL)". No very elegant, but the logging is for debugonly anyway.Dirk Niggemann
1 parent1c5aec6 commit63d7df4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

‎src/interfaces/odbc/connection.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#defineSTMT_INCREMENT 16/* how many statement holders to allocate at a time */
3131

32+
#definePRN_NULLCHECK
33+
3234
externGLOBAL_VALUESglobals;
3335

3436

@@ -1345,22 +1347,27 @@ static char *func = "CC_lookup_lo";
13451347
void
13461348
CC_log_error(char*func,char*desc,ConnectionClass*self)
13471349
{
1350+
#ifdefPRN_NULLCHECK
1351+
#definenullcheck(a) (a ? a : "(NULL)")
1352+
#endif
1353+
13481354
if (self) {
1349-
qlog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,self->errormsg);
1350-
mylog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,self->errormsg);
1355+
qlog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,nullcheck (self->errormsg));
1356+
mylog("CONN ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,nullcheck (self->errormsg));
13511357
qlog(" ------------------------------------------------------------\n");
13521358
qlog(" henv=%u, conn=%u, status=%u, num_stmts=%d\n",self->henv,self,self->status,self->num_stmts);
13531359
qlog(" sock=%u, stmts=%u, lobj_type=%d\n",self->sock,self->stmts,self->lobj_type);
13541360

13551361
qlog(" ---------------- Socket Info -------------------------------\n");
13561362
if (self->sock) {
13571363
SocketClass*sock=self->sock;
1358-
qlog(" socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n",sock->socket,sock->reverse,sock->errornumber,sock->errormsg);
1364+
qlog(" socket=%d, reverse=%d, errornumber=%d, errormsg='%s'\n",sock->socket,sock->reverse,sock->errornumber,nullcheck(sock->errormsg));
13591365
qlog(" buffer_in=%u, buffer_out=%u\n",sock->buffer_in,sock->buffer_out);
13601366
qlog(" buffer_filled_in=%d, buffer_filled_out=%d, buffer_read_in=%d\n",sock->buffer_filled_in,sock->buffer_filled_out,sock->buffer_read_in);
13611367
}
13621368
}
13631369
else
13641370
qlog("INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n",func,desc);
1371+
#undef PRN_NULLCHECK
13651372
}
13661373

‎src/interfaces/odbc/statement.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern GLOBAL_VALUES globals;
4141
#definestrnicmp(s1,s2,n)strncasecmp(s1,s2,n)
4242
#endif
4343
#endif
44+
#definePRN_NULLCHECK
4445

4546
/*Map sql commands to statement types */
4647
staticstruct {
@@ -899,28 +900,31 @@ QueryInfo qi;
899900
void
900901
SC_log_error(char*func,char*desc,StatementClass*self)
901902
{
903+
#ifdefPRN_NULLCHECK
904+
#definenullcheck(a) (a ? a : "(NULL)")
905+
#endif
902906
if (self) {
903-
qlog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,self->errormsg);
904-
mylog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,self->errormsg);
907+
qlog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,nullcheck(self->errormsg));
908+
mylog("STATEMENT ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n",func,desc,self->errornumber,nullcheck(self->errormsg));
905909
qlog(" ------------------------------------------------------------\n");
906910
qlog(" hdbc=%u, stmt=%u, result=%u\n",self->hdbc,self,self->result);
907911
qlog(" manual_result=%d, prepare=%d, internal=%d\n",self->manual_result,self->prepare,self->internal);
908912
qlog(" bindings=%u, bindings_allocated=%d\n",self->bindings,self->bindings_allocated);
909913
qlog(" parameters=%u, parameters_allocated=%d\n",self->parameters,self->parameters_allocated);
910-
qlog(" statement_type=%d, statement='%s'\n",self->statement_type,self->statement);
911-
qlog(" stmt_with_params='%s'\n",self->stmt_with_params);
914+
qlog(" statement_type=%d, statement='%s'\n",self->statement_type,nullcheck(self->statement));
915+
qlog(" stmt_with_params='%s'\n",nullcheck(self->stmt_with_params));
912916
qlog(" data_at_exec=%d, current_exec_param=%d, put_data=%d\n",self->data_at_exec,self->current_exec_param,self->put_data);
913917
qlog(" currTuple=%d, current_col=%d, lobj_fd=%d\n",self->currTuple,self->current_col,self->lobj_fd);
914918
qlog(" maxRows=%d, rowset_size=%d, keyset_size=%d, cursor_type=%d, scroll_concurrency=%d\n",self->options.maxRows,self->options.rowset_size,self->options.keyset_size,self->options.cursor_type,self->options.scroll_concurrency);
915-
qlog(" cursor_name='%s'\n",self->cursor_name);
919+
qlog(" cursor_name='%s'\n",nullcheck(self->cursor_name));
916920

917921
qlog(" ----------------QResult Info -------------------------------\n");
918922

919923
if (self->result) {
920924
QResultClass*res=self->result;
921925
qlog(" fields=%u, manual_tuples=%u, backend_tuples=%u, tupleField=%d, conn=%u\n",res->fields,res->manual_tuples,res->backend_tuples,res->tupleField,res->conn);
922-
qlog(" fetch_count=%d, fcount=%d, num_fields=%d, cursor='%s'\n",res->fetch_count,res->fcount,res->num_fields,res->cursor);
923-
qlog(" message='%s', command='%s', notice='%s'\n",res->message,res->command,res->notice);
926+
qlog(" fetch_count=%d, fcount=%d, num_fields=%d, cursor='%s'\n",res->fetch_count,res->fcount,res->num_fields,nullcheck(res->cursor));
927+
qlog(" message='%s', command='%s', notice='%s'\n",nullcheck(res->message),nullcheck(res->command),nullcheck(res->notice));
924928
qlog(" status=%d, inTuples=%d\n",res->status,res->inTuples);
925929
}
926930

@@ -929,5 +933,6 @@ SC_log_error(char *func, char *desc, StatementClass *self)
929933
}
930934
else
931935
qlog("INVALID STATEMENT HANDLE ERROR: func=%s, desc='%s'\n",func,desc);
936+
#undef PRN_NULLCHECK
932937
}
933938

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp