@@ -4738,10 +4738,10 @@ static int cdb2_send_query(cdb2_hndl_tp *hndl, cdb2_hndl_tp *event_hndl, COMDB2B
47384738 features [n_features ++ ] = CDB2_CLIENT_FEATURES__ALLOW_MASTER_EXEC ;
47394739 }
47404740
4741- if (hndl && hndl -> cnonce [ 0 ] ) { /* Have a query id associated with each transaction/query */
4741+ if (hndl && hndl -> cnonce_len > 0 ) { /* Have a query id associated with each transaction/query */
47424742 sqlquery .has_cnonce = 1 ;
47434743 sqlquery .cnonce .data = (uint8_t * )hndl -> cnonce ;
4744- sqlquery .cnonce .len = strlen ( hndl -> cnonce ) ;
4744+ sqlquery .cnonce .len = hndl -> cnonce_len ;
47454745 }
47464746
47474747 CDB2SQLQUERY__Snapshotinfo snapshotinfo ;
@@ -5286,12 +5286,20 @@ int cdb2_close(cdb2_hndl_tp *hndl)
52865286 return rc ;
52875287}
52885288
5289- void next_cnonce ( cdb2_hndl_tp * hndl )
5289+ static void make_random_str ( char * str , size_t str_sz , int * len )
52905290{
52915291 do_init_once (1 );
52925292 struct timeval tv ;
52935293 gettimeofday (& tv , NULL );
5294- sprintf (hndl -> cnonce , "%d-%d-%lld-%d" , _MACHINE_ID , _PID , (long long )tv .tv_usec , cdb2_random_int ());
5294+ int rc = snprintf (str , str_sz , "%d-%d-%lld-%d" , _MACHINE_ID , _PID , (long long )tv .tv_usec , cdb2_random_int ());
5295+ if (rc < 0 || (size_t )rc >= str_sz ) {
5296+ // should not be possible to go here. 100 bytes is more than enough to fit the string for all numbers.
5297+ LOG_CALL ("%s: snprintf failed or truncated (rc=%d str_sz=%zu)\n" , __func__ , rc , str_sz );
5298+ str [0 ] = '\0' ;
5299+ * len = 0 ;
5300+ } else {
5301+ * len = rc ;
5302+ }
52955303 return ;
52965304}
52975305
@@ -6132,7 +6140,7 @@ static int cdb2_run_statement_typed_int(cdb2_hndl_tp *hndl, const char *sql, int
61326140
61336141 if (!hndl -> in_trans ) { /* only one cnonce for a transaction. */
61346142 clear_snapshot_info (hndl , __LINE__ );
6135- next_cnonce (hndl );
6143+ make_random_str (hndl -> cnonce , sizeof ( hndl -> cnonce ), & hndl -> cnonce_len );
61366144 }
61376145 hndl -> retry_all = 1 ;
61386146 int run_last = 1 ;
0 commit comments