Skip to content

Commit 7a338da

Browse files
authored
Fix cli vulnerabilities 2 (#15461)
1 parent 68f8abc commit 7a338da

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

ydb/library/benchmarks/gen/tpcds-dbgen/build_support.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,16 @@ embed_string(char *szDest, char *szDist, int nValue, int nWeight, int nStream)
368368
char *szWord = NULL;
369369

370370
pick_distribution(&szWord, szDist, nValue, nWeight, nStream);
371-
nPosition = genrand_integer(NULL, DIST_UNIFORM, 0, strlen(szDest) - strlen(szWord) - 1, 0, nStream);
371+
int destLen = strlen(szDest);
372+
int wordLen = strlen(szWord);
373+
nPosition = genrand_integer(NULL, DIST_UNIFORM, 0, destLen - wordLen - 1, 0, nStream);
372374
strncpy(&szDest[nPosition], szWord, strlen(szWord));
373375

376+
// strncpy can technically make szDest not null-terminated
377+
// Even though it doesn't, due to nPosition + wordLen is less than destLen
378+
// Prevent passing unterminated string. Fixing coverity issue STRING_NULL
379+
szDest[destLen] = '\0';
380+
374381
return(0);
375382
}
376383

ydb/library/benchmarks/gen/tpcds-dbgen/tdefs.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ getTdefsByNumber(int nTable)
147147
}
148148
*/
149149

150+
int getStdefsMaxSize() {
151+
return (int)(sizeof(s_tdefs) / sizeof(s_tdefs[0]));
152+
}
153+
150154
void checkTdefsSize(int nTable) {
151155
// Prevent array overflow. Fixing coverity issue OVERRUN
152-
if (nTable < 0 || nTable >= (int)(sizeof(s_tdefs) / sizeof(s_tdefs[0]))) {
156+
if (nTable < 0 || nTable >= getStdefsMaxSize()) {
153157
INTERNAL("Array s_tdefs overflow");
154158
exit(EXIT_FAILURE);
155159
}
@@ -230,8 +234,8 @@ getTableFromColumn(int nColumn)
230234
{
231235
int i;
232236
tdef *pT;
233-
234-
for (i=0; i <= MAX_TABLE; i++)
237+
238+
for (i=0; i < S_BRAND + getStdefsMaxSize(); i++)
235239
{
236240
pT = getSimpleTdefsByNumber(i);
237241
if ((nColumn >= pT->nFirstColumn) && (nColumn <= pT->nLastColumn))

ydb/library/benchmarks/gen/tpcds-dbgen/w_datetbl.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ mk_w_date (void * row, ds_key_t index)
113113
r->d_fy_year = r->d_year;
114114
r->d_fy_quarter_seq = r->d_quarter_seq;
115115
r->d_fy_week_seq = r->d_week_seq;
116-
if (r->d_dow >= MAXINT) {
117-
INTERNAL("Int overflow for d_dow");
116+
if (r->d_dow >= 7) {
117+
INTERNAL("weekday_names array overflow");
118118
exit(EXIT_FAILURE);
119-
}
119+
}
120120
r->d_day_name = weekday_names[r->d_dow + 1];
121121
dist_member (&r->d_holiday, "calendar", day_index, 8);
122122
if ((r->d_dow == 5) || (r->d_dow == 6))
@@ -294,10 +294,10 @@ vld_w_date(int nTable, ds_key_t kRow, int *Permutation)
294294
r->d_fy_year = r->d_year;
295295
r->d_fy_quarter_seq = r->d_quarter_seq;
296296
r->d_fy_week_seq = r->d_week_seq;
297-
if (r->d_dow >= MAXINT) {
298-
INTERNAL("Int overflow for d_dow");
297+
if (r->d_dow >= 7) {
298+
INTERNAL("weekday_names array overflow");
299299
exit(EXIT_FAILURE);
300-
}
300+
}
301301
r->d_day_name = weekday_names[r->d_dow + 1];
302302
dist_member (&r->d_holiday, "calendar", day_index, 8);
303303
if ((r->d_dow == 5) || (r->d_dow == 6))

ydb/library/benchmarks/gen/tpcds-dbgen/w_item.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@
5858
struct W_ITEM_TBL g_w_item,
5959
g_OldValues;
6060

61-
void validate_string(char *szString, unsigned long maxSize) {
62-
// Prevent passing unterminated string. Fixing coverity issue STRING_NULL
63-
if (strlen(szString) > maxSize) {
64-
INTERNAL("Trying po pass unterminated string");
65-
exit(EXIT_FAILURE);
66-
}
67-
}
68-
6961
/*
7062
* mk_item
7163
*/
@@ -198,7 +190,6 @@ mk_w_item (void* row, ds_key_t index)
198190

199191
gen_charset(r->i_formulation, DIGITS, RS_I_FORMULATION, RS_I_FORMULATION, I_FORMULATION);
200192
embed_string(r->i_formulation, "colors", 1, 2, I_FORMULATION);
201-
validate_string(r->i_formulation, RS_I_FORMULATION);
202193
changeSCD(SCD_CHAR, &r->i_formulation, &rOldValues->i_formulation, &nFieldChangeFlags, bFirstRecord);
203194

204195
pick_distribution (&r->i_color, "colors", 1, 2, I_COLOR);

ydb/library/benchmarks/gen/tpch-dbgen/print.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ print_prep(int table, int update)
6969
this_segment=++insert_orders_segment;
7070
else
7171
this_segment=++insert_lineitem_segment;
72-
sprintf(upath, "%s%c%s.u%d.%d",
72+
snprintf(upath, 128, "%s%c%s.u%d.%d",
7373
env_config(PATH_TAG, PATH_DFLT),
7474
PATH_SEP, tdefs[table].name, update%10000,this_segment);
7575
}
@@ -83,13 +83,13 @@ print_prep(int table, int update)
8383
if ( delete_segments )
8484
{
8585
++delete_segment;
86-
sprintf(upath, "%s%cdelete.u%d.%d",
86+
snprintf(upath, 128, "%s%cdelete.u%d.%d",
8787
env_config(PATH_TAG, PATH_DFLT), PATH_SEP, -update%10000,
8888
delete_segment);
8989
}
9090
else
9191
{
92-
sprintf(upath, "%s%cdelete.%d",
92+
snprintf(upath, 128, "%s%cdelete.%d",
9393
env_config(PATH_TAG, PATH_DFLT), PATH_SEP, -update);
9494
}
9595
return(fopen(upath, "w"));

0 commit comments

Comments
 (0)