Skip to content

Commit 32d9ff2

Browse files
committed
Some code hardening with enum rwl_type
1 parent 7eed3e2 commit 32d9ff2

File tree

4 files changed

+137
-26
lines changed

4 files changed

+137
-26
lines changed

src/rwl.h

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*
1414
* History
1515
*
16+
* bengsig 3-nov-2022 - Harden code with rwl_type throughout
1617
* bengsig 31-oct-2022 - Add better queue time via $queueeverytiming:on
1718
* bengsig 26-oct-2022 - Add $niceabort:on directive
1819
* bengsig 18-oct-2022 - threads global variables
@@ -280,6 +281,30 @@ struct rwl_location
280281
ub4 inpos; // position on line
281282
};
282283

284+
// types
285+
enum rwl_type
286+
{
287+
RWL_TYPE_NONE = 0
288+
, RWL_TYPE_INT = 1 /* integer (sb8) */
289+
, RWL_TYPE_DBL = 2 /* double */
290+
, RWL_TYPE_STR = 3 /* string */
291+
#define RWL_DEFAULT_STRLEN 128 // if length not specified
292+
, RWL_TYPE_PROC = 4 /* procedure */
293+
, RWL_TYPE_SQL = 5 /* sql */
294+
, RWL_TYPE_RAST = 6 /* random string array */
295+
, RWL_TYPE_RAPROC = 7 /* random procedure array */
296+
, RWL_TYPE_CANCELLED = 8 /* cancelled something due to error */
297+
, RWL_TYPE_DB = 9 /* database */
298+
, RWL_TYPE_FILE = 10 /* file for writing */
299+
//, RWL_TYPE_unused11 = 11
300+
, RWL_TYPE_FUNC = 12 /* function with return value */
301+
, RWL_TYPE_CLOB = 13
302+
, RWL_TYPE_BLOB = 14
303+
, RWL_TYPE_NCLOB = 15
304+
, RWL_TYPE_RAW = 16 /* raw - currently only used under hack flag -D 0x1 */
305+
, RWL_TYPE_STREND = 17 // not a type, only used in rwldoprintf
306+
};
307+
283308
enum rwl_pooltype
284309
{
285310
RWL_DBPOOL_NONE = 0
@@ -388,13 +413,13 @@ struct rwl_value
388413
* sval is the actual buffer
389414
*/
390415
rwl_vsalloc vsalloc; /* how was sval allocated */
416+
rwl_type vtype; /* dominant type - one of RWL_TYPE_{INT,DBL,STR} */
391417
ub1 valflags;
392418
#define RWL_VALUE_FILE_OPENR 0x01 /* if this is a file, it is open for read */
393419
#define RWL_VALUE_FILE_OPENW 0x02 /* if this is a file, it is open for write */
394420
#define RWL_VALUE_FILEISPIPE 0x04 /* if this is a file, it is a pipe */
395421
#define RWL_VALUE_FILEREPNOTOPEN 0x08 /* set when file not open has been reported during write */
396422
#define RWL_VALUE_FILEOPENMAIN 0x10 /* set when the file was opened in main */
397-
ub1 vtype; /* dominant type - one of RWL_TYPE_{INT,DBL,STR} */
398423
sb2 isnull; /* false when good and not NULL */
399424
#define RWL_ISNULL (-1) // MUST match the Oracle definition
400425
#ifdef RWL_USE_BIN_DEF_OCI2
@@ -598,6 +623,7 @@ struct rwl_bindef
598623
text *bname; /* named bind */
599624
ub4 pos; /* define or positional bind */
600625
rwl_bindef *next; /* linked list */
626+
rwl_type vtype; /* variable type (set from variable or direct) */
601627
ub1 bdtyp; /* one of these */
602628
#define RWL_BIND_POS 1 /* bind by position */
603629
#define RWL_BIND_NAME 2 /* bind by name */
@@ -620,7 +646,6 @@ struct rwl_bindef
620646
*/
621647
#define RWL_DIRBIND 15 /* bind direct by position */
622648
#define RWL_DIRDEFINE 16 /* define direct by position */
623-
ub1 vtype; /* variable type (set from variable or direct) */
624649
ub1 bdflags;
625650
#define RWL_BDFLAG_BNALLOC 0x01 // bname was rwlstrdup'ed and must be freed
626651
#define RWL_BDFLAG_FIXED 0x02 // fixed at declaration time
@@ -1072,30 +1097,6 @@ struct rwl_pvariable
10721097
rwl_location loc; /* location of declaration */
10731098
};
10741099

1075-
// types
1076-
enum rwl_type
1077-
{
1078-
RWL_TYPE_NONE = 0
1079-
, RWL_TYPE_INT = 1 /* integer (sb8) */
1080-
, RWL_TYPE_DBL = 2 /* double */
1081-
, RWL_TYPE_STR = 3 /* string */
1082-
#define RWL_DEFAULT_STRLEN 128 // if length not specified
1083-
, RWL_TYPE_PROC = 4 /* procedure */
1084-
, RWL_TYPE_SQL = 5 /* sql */
1085-
, RWL_TYPE_RAST = 6 /* random string array */
1086-
, RWL_TYPE_RAPROC = 7 /* random procedure array */
1087-
, RWL_TYPE_CANCELLED = 8 /* cancelled something due to error */
1088-
, RWL_TYPE_DB = 9 /* database */
1089-
, RWL_TYPE_FILE = 10 /* file for writing */
1090-
//, RWL_TYPE_unused11 = 11
1091-
, RWL_TYPE_FUNC = 12 /* function with return value */
1092-
, RWL_TYPE_CLOB = 13
1093-
, RWL_TYPE_BLOB = 14
1094-
, RWL_TYPE_NCLOB = 15
1095-
, RWL_TYPE_RAW = 16 /* raw - currently only used under hack flag -D 0x1 */
1096-
, RWL_TYPE_STREND = 17 // not a type, only used in rwldoprintf
1097-
};
1098-
10991100
/* identifiers
11001101
*
11011102
* these are stored in the execution time context

src/rwlcoderun.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* History
1616
*
17+
* bengsig 3-nov-2022 - Harden code with rwl_type throughout
1718
* bengsig 31-oct-2022 - Add better queue time via $queueeverytiming:on
1819
* bengsig 26-oct-2022 - Add $niceabort:on directive
1920
* bengsig 18-oct-2022 - threads global variables
@@ -2585,6 +2586,9 @@ void rwllocalsprepare(rwl_xeqenv *xev
25852586
nn->sval = rwlalloc(xev->rwm, RWL_PFBUF);
25862587
nn->vsalloc = RWL_SVALLOC_FIX;
25872588
break;
2589+
2590+
default:
2591+
break;
25882592
}
25892593
}
25902594
} /* for pp over all locals */

src/rwlexpreval.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* History
1616
*
17+
* bengsig 3-nov-2022 - Harden code with rwl_type throughout
1718
* bengsig 18-oct-2022 - threads global variables
1819
* bengsig 22-sep-2022 - Deal better with types in stack evaluation
1920
* bengsig 16-sep-2022 - Don't call rwlenvexp on RWL_T_PIPETO
@@ -1417,6 +1418,9 @@ void rwlexpreval ( rwl_estack *stk , rwl_location *loc , rwl_xeqenv *xev , rwl_v
14171418
: vv->vname
14181419
);
14191420
break;
1421+
1422+
default:
1423+
break;
14201424
}
14211425
if (bit(xev->tflags,RWL_THR_DEVAL))
14221426
{
@@ -1480,6 +1484,9 @@ void rwlexpreval ( rwl_estack *stk , rwl_location *loc , rwl_xeqenv *xev , rwl_v
14801484
nn->vsalloc = RWL_SVALLOC_FIX;
14811485
rwlstrnncpy(nn->sval, ss->sval, nn->slen);
14821486
break;
1487+
1488+
default:
1489+
break;
14831490
}
14841491
if (bit(xev->tflags,RWL_THR_DEVAL))
14851492
rwldebugcode(xev->rwm, loc
@@ -1559,6 +1566,9 @@ void rwlexpreval ( rwl_estack *stk , rwl_location *loc , rwl_xeqenv *xev , rwl_v
15591566
nn->vptr = 0;
15601567
}
15611568
break;
1569+
1570+
default:
1571+
break;
15621572
}
15631573
}
15641574
rwlfree(xev->rwm, xev->locals[xev->pcdepth]);

src/rwlsql.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*
1212
* History
1313
*
14+
* bengsig 3-nov-2022 - Harden code with rwl_type throughout
1415
* bengsig 18-oct-2022 - threads global variables
1516
* bengsig 12-oct-2022 - session leak
1617
* bengsig 11-jul-2022 - $sessionpool_no_rlb directive
@@ -1147,6 +1148,11 @@ static void rwlexecsql(rwl_xeqenv *xev
11471148
if (OCI_SUCCESS != xev->status)
11481149
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
11491150
break;
1151+
1152+
default:
1153+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype7:%s;%s;%d]"
1154+
, sq->vname, bd->vname, bd->vtype);
1155+
break;
11501156
}
11511157
break;
11521158

@@ -1217,6 +1223,11 @@ static void rwlexecsql(rwl_xeqenv *xev
12171223
if (OCI_SUCCESS != xev->status)
12181224
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
12191225
break;
1226+
1227+
default:
1228+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype6:%s;%s;%d]"
1229+
, sq->vname, bd->vname, bd->vtype);
1230+
break;
12201231
}
12211232
break;
12221233

@@ -1284,6 +1295,11 @@ static void rwlexecsql(rwl_xeqenv *xev
12841295
if (OCI_SUCCESS != xev->status)
12851296
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
12861297
break;
1298+
1299+
default:
1300+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype5:%s;%s;%d]"
1301+
, sq->vname, bd->vname, bd->vtype);
1302+
break;
12871303
}
12881304
break;
12891305

@@ -1463,6 +1479,11 @@ static void rwlexecsql(rwl_xeqenv *xev
14631479
if (OCI_SUCCESS != xev->status)
14641480
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
14651481
break;
1482+
1483+
default:
1484+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype4:%s;%s;%d]"
1485+
, sq->vname, bd->vname, bd->vtype);
1486+
break;
14661487
}
14671488
break;
14681489

@@ -1518,6 +1539,11 @@ static void rwlexecsql(rwl_xeqenv *xev
15181539
if (OCI_SUCCESS != xev->status)
15191540
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
15201541
break;
1542+
1543+
default:
1544+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype4:%s;%s;%d]"
1545+
, sq->vname, bd->vname, bd->vtype);
1546+
break;
15211547
}
15221548
}
15231549
else // not using define/fetch array
@@ -1571,6 +1597,11 @@ static void rwlexecsql(rwl_xeqenv *xev
15711597
if (OCI_SUCCESS != xev->status)
15721598
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
15731599
break;
1600+
1601+
default:
1602+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype3:%s;%s;%d]"
1603+
, sq->vname, bd->vname, bd->vtype);
1604+
break;
15741605
}
15751606
}
15761607
dc++;
@@ -1784,6 +1815,7 @@ static void rwlexecsql(rwl_xeqenv *xev
17841815
case RWL_TYPE_BLOB:
17851816
case RWL_TYPE_CLOB:
17861817
pi->vdata = db; // such that READ/WRITE LOB has it
1818+
default:
17871819
break;
17881820
}
17891821
}
@@ -1918,6 +1950,15 @@ static void rwlexecsql(rwl_xeqenv *xev
19181950
pnum->ival=rwlatosb8(pnum->sval);
19191951
pnum->isnull = 0; /* rwloadsim doesn't have empty string as NULL */
19201952
break;
1953+
1954+
case RWL_TYPE_BLOB:
1955+
case RWL_TYPE_NCLOB:
1956+
break;
1957+
1958+
default:
1959+
rwlexecsevere(xev, cloc, "[rwlexecsql-badcopydef:%s;%s;%d]"
1960+
, sq->vname, bd->vname, bd->vtype);
1961+
break;
19211962
}
19221963
dc++;
19231964
}
@@ -2082,6 +2123,7 @@ static void rwlexecsql(rwl_xeqenv *xev
20822123
case RWL_TYPE_BLOB:
20832124
case RWL_TYPE_CLOB:
20842125
pi->vdata = db; // such that READ/WRITE LOB has it
2126+
default:
20852127
break;
20862128
}
20872129
bd=bd->next;
@@ -2122,6 +2164,11 @@ static void rwlexecsql(rwl_xeqenv *xev
21222164
}
21232165
pnum->isnull = 0;
21242166
break;
2167+
2168+
default:
2169+
rwlexecsevere(xev, cloc, "[rwlexecsql-badtype1:%s;%s;%d]"
2170+
, sq->vname, bd->vname, bd->vtype);
2171+
break;
21252172
}
21262173
bd=bd->next; i++;
21272174
}
@@ -2144,6 +2191,9 @@ static void rwlexecsql(rwl_xeqenv *xev
21442191
case RWL_TYPE_CLOB:
21452192
pi->vdata = db; // such that READ/WRITE LOB has it
21462193
break;
2194+
2195+
default:
2196+
break;
21472197
}
21482198
}
21492199
break;
@@ -2258,6 +2308,17 @@ static void rwlexecsql(rwl_xeqenv *xev
22582308
pnum->dval=rwlatof(pnum->sval);
22592309
pnum->ival=rwlatosb8(pnum->sval);
22602310
break;
2311+
2312+
case RWL_TYPE_CLOB:
2313+
case RWL_TYPE_NCLOB:
2314+
case RWL_TYPE_BLOB:
2315+
2316+
break;
2317+
2318+
default:
2319+
rwlexecsevere(xev, cloc, "[rwlexecslq-badtyp2:%s;%s;%d]"
2320+
, sq->vname, bd->vname, bd->vtype);
2321+
break;
22612322
}
22622323
}
22632324
bd=bd->next; i++;
@@ -2408,6 +2469,11 @@ void rwlflushsql2(rwl_xeqenv *xev
24082469
if (OCI_SUCCESS != xev->status)
24092470
{ rwldberror2(xev, cloc, sq, fname); goto failure; }
24102471
break;
2472+
2473+
default:
2474+
rwlexecsevere(xev, cloc, "[rwlflushsql-badtyp0:%s;%s;%d]"
2475+
, sq->vname, bd->vname, bd->vtype);
2476+
break;
24112477
}
24122478
break;
24132479

@@ -2451,6 +2517,11 @@ void rwlflushsql2(rwl_xeqenv *xev
24512517
rwlexecsevere(xev, cloc, "[rwlflushsql-notraw1:%s;%s]"
24522518
, sq->vname, bd->vname);
24532519
break;
2520+
2521+
default:
2522+
rwlexecsevere(xev, cloc, "[rwlflushsql-badtyp1:%s;%s;%d]"
2523+
, sq->vname, bd->vname, bd->vtype);
2524+
break;
24542525
}
24552526
break;
24562527

@@ -2497,6 +2568,11 @@ void rwlflushsql2(rwl_xeqenv *xev
24972568
rwlexecsevere(xev, cloc, "[rwlflushsql-notraw2:%s;%s]"
24982569
, sq->vname, bd->vname);
24992570
break;
2571+
2572+
default:
2573+
rwlexecsevere(xev, cloc, "[rwlflushsql-badtyp2:%s;%s;%d]"
2574+
, sq->vname, bd->vname, bd->vtype);
2575+
break;
25002576
}
25012577
break;
25022578

@@ -2749,6 +2825,11 @@ void rwlsimplesql2(rwl_xeqenv *xev
27492825
rwlstrnncpy((text *)sq->abd[b] + sq->aix*bd->slen, bd->pvar, bd->slen);
27502826
((sb2 *)sq->ari[b])[sq->aix] = *bd->pind;
27512827
break;
2828+
2829+
default:
2830+
rwlexecsevere(xev, cloc, "[rwlsimplesql2-copydir:%s;%d]"
2831+
, sq->vname, bd->vtype);
2832+
break;
27522833
}
27532834
break;
27542835

@@ -2777,6 +2858,11 @@ void rwlsimplesql2(rwl_xeqenv *xev
27772858
case RWL_TYPE_BLOB:
27782859

27792860
break;
2861+
2862+
default:
2863+
rwlexecsevere(xev, cloc, "[rwlsimplesql2-copyval:%s;%d]"
2864+
, sq->vname, bd->bdtyp);
2865+
break;
27802866
}
27812867
break;
27822868

@@ -3646,6 +3732,11 @@ void rwlallocabd(rwl_xeqenv *xev, rwl_location *loc, rwl_sql *sq)
36463732
sq->abd[bdn] = (void *)rwlalloc(xev->rwm, sq->asiz*bd->slen);
36473733
sq->ari[bdn] = (sb2 *) rwlalloc(xev->rwm, sq->asiz*sizeof(sb2));
36483734
break;
3735+
3736+
default:
3737+
rwlexecsevere(xev, loc, "[rwlallocabd-badtype:%s;%d]"
3738+
, sq->vname, bd->vtype);
3739+
break;
36493740
}
36503741
bdn++;
36513742
}
@@ -3689,6 +3780,9 @@ void rwlallocabd(rwl_xeqenv *xev, rwl_location *loc, rwl_sql *sq)
36893780
sq->abd[bdn] = (void *)rwlalloc(xev->rwm, sq->asiz*bd->slen);
36903781
sq->ari[bdn] = (sb2 *) rwlalloc(xev->rwm, sq->asiz*sizeof(sb2));
36913782
break;
3783+
3784+
default:
3785+
break;
36923786
}
36933787
bdn++;
36943788
}
@@ -3752,6 +3846,8 @@ void rwlfreeabd(rwl_xeqenv *xev, rwl_location *loc, rwl_sql *sq)
37523846
rwlfree(xev->rwm, sq->ari[bdn]);
37533847
break;
37543848

3849+
default:
3850+
break;
37553851
}
37563852
bdn++;
37573853
break;

0 commit comments

Comments
 (0)