@@ -283,6 +283,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
283
283
int tokens ;
284
284
unsigned int hour = 0 , min = 0 , sec = 0 ;
285
285
tokens = sscanf (row [i ], "%2u:%2u:%2u" , & hour , & min , & sec );
286
+ if (tokens < 3 ) {
287
+ val = Qnil ;
288
+ break ;
289
+ }
286
290
val = rb_funcall (rb_cTime , db_timezone , 6 , opt_time_year , opt_time_month , opt_time_month , UINT2NUM (hour ), UINT2NUM (min ), UINT2NUM (sec ));
287
291
if (!NIL_P (app_timezone )) {
288
292
if (app_timezone == intern_local ) {
@@ -300,6 +304,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
300
304
uint64_t seconds ;
301
305
302
306
tokens = sscanf (row [i ], "%4u-%2u-%2u %2u:%2u:%2u.%6u" , & year , & month , & day , & hour , & min , & sec , & msec );
307
+ if (tokens < 6 ) { /* msec might be empty */
308
+ val = Qnil ;
309
+ break ;
310
+ }
303
311
seconds = (year * 31557600ULL ) + (month * 2592000ULL ) + (day * 86400ULL ) + (hour * 3600ULL ) + (min * 60ULL ) + sec ;
304
312
305
313
if (seconds == 0 ) {
@@ -342,6 +350,10 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
342
350
int tokens ;
343
351
unsigned int year = 0 , month = 0 , day = 0 ;
344
352
tokens = sscanf (row [i ], "%4u-%2u-%2u" , & year , & month , & day );
353
+ if (tokens < 3 ) {
354
+ val = Qnil ;
355
+ break ;
356
+ }
345
357
if (year + month + day == 0 ) {
346
358
val = Qnil ;
347
359
} else {
0 commit comments