@@ -73,7 +73,7 @@ Persistent<FunctionTemplate> Connection::connectionTemplate_s;
73
73
74
74
#define NJS_SIZE_T_MAX std::numeric_limits<std::size_t >::max()
75
75
76
- #define NJS_IS_SIZE_T_OVERFLOW (maxSize,maxRows ) \
76
+ #define NJS_SIZE_T_OVERFLOW (maxSize,maxRows ) \
77
77
( ( ( maxSize != 0 ) && \
78
78
( ( ( NJS_SIZE_T_MAX ) / ( (size_t )maxSize ) ) < (maxRows) ) ) ? 1 : 0 ) \
79
79
@@ -1397,20 +1397,25 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1397
1397
1398
1398
defines[col].maxSize = sizeof (double );
1399
1399
1400
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1400
+ if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1401
1401
executeBaton->maxRows ) )
1402
1402
{
1403
- defines[col]. buf = ( double *) malloc ( ( size_t )defines[col]. maxSize *
1404
- executeBaton-> maxRows ) ;
1403
+ executeBaton-> error = NJSMessages::getErrorMsg ( errResultsTooLarge );
1404
+ return ;
1405
1405
}
1406
1406
else
1407
- defines[col].buf = 0 ;
1408
-
1409
- if (!defines[col].buf )
1410
1407
{
1411
- executeBaton->error = NJSMessages::getErrorMsg (errInsufficientMemory);
1412
- return ;
1408
+ defines[col].buf = (double *)malloc ( (size_t )defines[col].maxSize *
1409
+ executeBaton->maxRows );
1410
+
1411
+ if ( !defines[col].buf )
1412
+ {
1413
+ executeBaton->error = NJSMessages::getErrorMsg (
1414
+ errInsufficientMemory );
1415
+ return ;
1416
+ }
1413
1417
}
1418
+
1414
1419
break ;
1415
1420
case dpi::DpiVarChar :
1416
1421
case dpi::DpiFixedChar :
@@ -1425,19 +1430,22 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1425
1430
1426
1431
defines[col].maxSize = (meta[col].dbSize ) * NJS_CHAR_CONVERSION_RATIO;
1427
1432
1428
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1433
+ if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1429
1434
executeBaton->maxRows ) )
1430
1435
{
1431
- defines[col]. buf = ( char *) malloc ( ( size_t )defines[col]. maxSize *
1432
- executeBaton-> maxRows ) ;
1436
+ executeBaton-> error = NJSMessages::getErrorMsg ( errResultsTooLarge );
1437
+ return ;
1433
1438
}
1434
1439
else
1435
- defines[col].buf = 0 ;
1436
-
1437
- if (!defines[col].buf )
1438
1440
{
1439
- executeBaton->error = NJSMessages::getErrorMsg (errInsufficientMemory);
1440
- return ;
1441
+ defines[col].buf = (char *)malloc ( (size_t )defines[col].maxSize *
1442
+ executeBaton->maxRows );
1443
+ if ( !defines[col].buf )
1444
+ {
1445
+ executeBaton->error = NJSMessages::getErrorMsg (
1446
+ errInsufficientMemory );
1447
+ return ;
1448
+ }
1441
1449
}
1442
1450
break ;
1443
1451
case dpi::DpiDate :
@@ -1473,21 +1481,25 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1473
1481
/* Fetching DATE/TIMESTAMP values as VARCHAR */
1474
1482
defines[col].maxSize = NJS_MAX_FETCH_AS_STRING_SIZE ;
1475
1483
1476
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1484
+ if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1477
1485
executeBaton->maxRows ) )
1478
1486
{
1479
- defines[col]. buf = ( char *) malloc ( ( size_t )defines[col]. maxSize *
1480
- executeBaton-> maxRows ) ;
1487
+ executeBaton-> error = NJSMessages::getErrorMsg ( errResultsTooLarge );
1488
+ return ;
1481
1489
}
1482
1490
else
1483
- defines[col].buf = 0 ;
1484
-
1485
- if (!defines[col].buf )
1486
1491
{
1487
- executeBaton->error = NJSMessages::getErrorMsg (
1488
- errInsufficientMemory);
1489
- return ;
1492
+ defines[col].buf = (char *)malloc ( (size_t )defines[col].maxSize *
1493
+ executeBaton->maxRows );
1494
+
1495
+ if ( !defines[col].buf )
1496
+ {
1497
+ executeBaton->error = NJSMessages::getErrorMsg (
1498
+ errInsufficientMemory);
1499
+ return ;
1500
+ }
1490
1501
}
1502
+
1491
1503
}
1492
1504
break ;
1493
1505
@@ -1497,19 +1509,22 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1497
1509
defines[col].fetchType = meta[col].dbType ;
1498
1510
defines[col].maxSize = sizeof (Descriptor *);
1499
1511
1500
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1512
+ if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1501
1513
executeBaton->maxRows ) )
1502
1514
{
1503
- defines[col]. buf = malloc ( ( size_t )defines[col]. maxSize *
1504
- executeBaton-> maxRows ) ;
1515
+ executeBaton-> error = NJSMessages::getErrorMsg ( errResultsTooLarge );
1516
+ return ;
1505
1517
}
1506
1518
else
1507
- defines[col].buf = 0 ;
1508
-
1509
- if (!defines[col].buf )
1510
1519
{
1511
- executeBaton->error = NJSMessages::getErrorMsg (errInsufficientMemory);
1512
- return ;
1520
+ defines[col].buf = malloc ( (size_t )defines[col].maxSize *
1521
+ executeBaton->maxRows );
1522
+
1523
+ if ( !defines[col].buf )
1524
+ {
1525
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
1526
+ return ;
1527
+ }
1513
1528
}
1514
1529
1515
1530
for (unsigned int j = 0 ; j < executeBaton->maxRows ; j++)
@@ -1531,20 +1546,23 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1531
1546
}
1532
1547
defines[col].maxSize = NJS_MAX_FETCH_AS_STRING_SIZE;
1533
1548
1534
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1549
+ if ( NJS_SIZE_T_OVERFLOW ( defines[col].maxSize ,
1535
1550
executeBaton->maxRows ) )
1536
1551
{
1537
- defines[col]. buf = ( char *) malloc ( ( size_t )defines[col]. maxSize *
1538
- executeBaton-> maxRows ) ;
1552
+ executeBaton-> error = NJSMessages::getErrorMsg ( errResultsTooLarge );
1553
+ return ;
1539
1554
}
1540
1555
else
1541
- defines[col].buf = 0 ;
1542
-
1543
- if (!defines[col].buf )
1544
1556
{
1545
- executeBaton->error = NJSMessages::getErrorMsg (
1546
- errInsufficientMemory);
1547
- return ;
1557
+ defines[col].buf = (char *)malloc ( (size_t )defines[col].maxSize *
1558
+ executeBaton->maxRows );
1559
+
1560
+ if ( !defines[col].buf )
1561
+ {
1562
+ executeBaton->error = NJSMessages::getErrorMsg (
1563
+ errInsufficientMemory);
1564
+ return ;
1565
+ }
1548
1566
}
1549
1567
break ;
1550
1568
@@ -1557,14 +1575,14 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
1557
1575
defines[col].ind = (short *)malloc (sizeof (short )*(executeBaton->maxRows ));
1558
1576
if (!defines[col].ind )
1559
1577
{
1560
- executeBaton->error = NJSMessages::getErrorMsg (errInsufficientMemory);
1578
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
1561
1579
return ;
1562
1580
}
1563
1581
defines[col].len = (DPI_BUFLEN_TYPE *)malloc (sizeof (DPI_BUFLEN_TYPE)*
1564
1582
executeBaton->maxRows );
1565
1583
if (!defines[col].len )
1566
1584
{
1567
- executeBaton->error = NJSMessages::getErrorMsg (errInsufficientMemory);
1585
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
1568
1586
return ;
1569
1587
}
1570
1588
@@ -2799,10 +2817,36 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
2799
2817
eBaton *executeBaton = (eBaton *)ctx;
2800
2818
Bind *bind = (Bind *)executeBaton->binds [bndpos];
2801
2819
2802
- bind->ind = (short *)malloc ( nRows * sizeof ( short ) ) ;
2820
+ if ( NJS_SIZE_T_OVERFLOW ( nRows, sizeof ( short )))
2821
+ {
2822
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2823
+ return ;
2824
+ }
2825
+ else
2826
+ {
2827
+ bind->ind = (short *)malloc ( nRows * sizeof ( short ) ) ;
2828
+ if ( !bind->ind )
2829
+ {
2830
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2831
+ return ;
2832
+ }
2833
+ }
2803
2834
if ( dmlReturning )
2804
2835
{
2805
- bind->len2 = ( unsigned int *)malloc ( nRows * sizeof ( unsigned int ) );
2836
+ if ( NJS_SIZE_T_OVERFLOW ( nRows, sizeof ( unsigned int )))
2837
+ {
2838
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2839
+ return ;
2840
+ }
2841
+ else
2842
+ {
2843
+ bind->len2 = ( unsigned int *)malloc ( nRows * sizeof ( unsigned int ) );
2844
+ if ( !bind->len2 )
2845
+ {
2846
+ executeBaton->error = NJSMessages::getErrorMsg ( errInsufficientMemory );
2847
+ return ;
2848
+ }
2849
+ }
2806
2850
}
2807
2851
else
2808
2852
{
@@ -2815,18 +2859,20 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
2815
2859
case dpi::DpiVarChar:
2816
2860
/* one extra char for EOS */
2817
2861
2818
- if ( ! NJS_IS_SIZE_T_OVERFLOW ( (bind->maxSize + 1 ), nRows) )
2862
+ if ( NJS_SIZE_T_OVERFLOW ( (bind->maxSize + 1 ), nRows) )
2819
2863
{
2820
- bind->value = (char *)malloc ( (size_t )( bind->maxSize + 1 ) * nRows );
2864
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2865
+ return ;
2821
2866
}
2822
2867
else
2823
- bind->value = 0 ;
2824
-
2825
- if ( !bind->value )
2826
2868
{
2827
- executeBaton->error = NJSMessages::getErrorMsg (
2828
- errInsufficientMemory);
2829
- return ;
2869
+ bind->value = (char *)malloc ( (size_t )( bind->maxSize + 1 ) * nRows );
2870
+ if ( !bind->value )
2871
+ {
2872
+ executeBaton->error = NJSMessages::getErrorMsg (
2873
+ errInsufficientMemory);
2874
+ return ;
2875
+ }
2830
2876
}
2831
2877
2832
2878
if ( dmlReturning )
@@ -2840,23 +2886,69 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
2840
2886
break ;
2841
2887
2842
2888
case dpi::DpiInteger:
2843
- bind->value = ( int *) malloc ( sizeof (int ) * nRows ) ;
2889
+ if ( NJS_SIZE_T_OVERFLOW ( sizeof (int ), nRows) )
2890
+ {
2891
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2892
+ return ;
2893
+ }
2894
+ else
2895
+ {
2896
+ bind->value = ( int *) malloc ( sizeof (int ) * nRows ) ;
2897
+ if ( !bind->value )
2898
+ {
2899
+ executeBaton->error = NJSMessages::getErrorMsg (
2900
+ errInsufficientMemory);
2901
+ return ;
2902
+ }
2903
+ }
2844
2904
if ( !dmlReturning )
2845
2905
{
2846
2906
*(bind->len ) = sizeof ( int ) ;
2847
2907
}
2848
2908
break ;
2849
2909
2850
2910
case dpi::DpiUnsignedInteger:
2851
- bind->value = ( unsigned int *)malloc ( sizeof ( unsigned int ) * nRows );
2911
+ if ( NJS_SIZE_T_OVERFLOW ( sizeof ( unsigned int ), nRows) )
2912
+ {
2913
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2914
+ return ;
2915
+ }
2916
+ else
2917
+ {
2918
+ bind->value = ( unsigned int *)malloc ( sizeof ( unsigned int ) * nRows );
2919
+ if ( !bind->value )
2920
+ {
2921
+ executeBaton->error = NJSMessages::getErrorMsg (
2922
+ errInsufficientMemory);
2923
+ return ;
2924
+ }
2925
+ }
2852
2926
if ( !dmlReturning )
2853
2927
{
2854
2928
*(bind->len ) = sizeof ( unsigned int ) ;
2855
2929
}
2856
2930
break ;
2857
2931
2858
2932
case dpi::DpiDouble:
2859
- bind->value = ( double *)malloc ( sizeof ( double ) * nRows );
2933
+ if ( NJS_SIZE_T_OVERFLOW ( sizeof ( double ), nRows) )
2934
+ {
2935
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2936
+ return ;
2937
+ }
2938
+ else
2939
+ {
2940
+ bind->value = ( double *)malloc ( sizeof ( double ) * nRows );
2941
+ if ( !bind->value )
2942
+ {
2943
+ executeBaton->error = NJSMessages::getErrorMsg (
2944
+ errInsufficientMemory);
2945
+ return ;
2946
+ }
2947
+ }
2948
+ if ( !dmlReturning )
2949
+ {
2950
+ *(bind->len ) = sizeof ( unsigned int ) ;
2951
+ }
2860
2952
if ( !dmlReturning )
2861
2953
{
2862
2954
*(bind->len ) = sizeof ( double ) ;
@@ -2872,7 +2964,21 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
2872
2964
if (nRows > 1 )
2873
2965
bind->rowsReturned = nRows;
2874
2966
// allocate the array of Descriptor **
2875
- bind->value = (void *)malloc (sizeof (Descriptor *) * bind->rowsReturned );
2967
+ if ( NJS_SIZE_T_OVERFLOW ( sizeof ( Descriptor * ), nRows) )
2968
+ {
2969
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
2970
+ return ;
2971
+ }
2972
+ else
2973
+ {
2974
+ bind->value = (void *)malloc (sizeof (Descriptor *) * bind->rowsReturned );
2975
+ if ( !bind->value )
2976
+ {
2977
+ executeBaton->error = NJSMessages::getErrorMsg (
2978
+ errInsufficientMemory);
2979
+ return ;
2980
+ }
2981
+ }
2876
2982
// and allocate the underlying descriptor(s)
2877
2983
for (unsigned int rowsidx = 0 ; rowsidx < bind->rowsReturned ; rowsidx++)
2878
2984
{
@@ -2887,8 +2993,22 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
2887
2993
break ;
2888
2994
2889
2995
case dpi::DpiTimestampLTZ:
2996
+ {
2997
+ if ( NJS_SIZE_T_OVERFLOW ( sizeof ( long double ), nRows) )
2998
+ {
2999
+ executeBaton->error = NJSMessages::getErrorMsg ( errResultsTooLarge );
3000
+ return ;
3001
+ }
3002
+ else
2890
3003
{
2891
3004
bind->extvalue = (long double *) malloc ( sizeof ( long double ) * nRows );
3005
+ if ( !bind->extvalue )
3006
+ {
3007
+ executeBaton->error = NJSMessages::getErrorMsg (
3008
+ errInsufficientMemory);
3009
+ return ;
3010
+ }
3011
+ }
2892
3012
// needed to post-process DML RETURNING of TimestampLTZ
2893
3013
// rowsReturns for INSERT will be zero,
2894
3014
// but we still need to allocate one descriptor
0 commit comments