Skip to content

Commit a49df0c

Browse files
sirus20x6pd3
authored andcommitted
Fix two bugs in regidx.c: OOB array access and double-free
1. regidx_overlap: cap iend to nidx-1 instead of nidx, preventing an out-of-bounds read of list->idx[nidx] in the i<=iend loop. 2. regidx_init: set str.s = NULL after freeing it so the error path does not double-free when hts_close() fails.
1 parent ceab492 commit a49df0c

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

regidx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f fr
289289
}
290290

291291
free(str.s);
292+
str.s = NULL;
292293
if ( hts_close(fp)!=0 )
293294
{
294295
fprintf(stderr,"[%s] Error: close failed .. %s\n", __func__,fname);
@@ -441,7 +442,7 @@ int regidx_overlap(regidx_t *regidx, const char *chr, uint32_t beg, uint32_t end
441442
if ( !i )
442443
{
443444
int iend = iBIN(end);
444-
if ( iend > list->nidx ) iend = list->nidx;
445+
if ( iend >= list->nidx ) iend = list->nidx - 1;
445446
for (i=ibeg; i<=iend; i++)
446447
if ( list->idx[i] ) break;
447448
if ( i>iend ) return 0;

0 commit comments

Comments
 (0)