Skip to content

Commit d40d998

Browse files
authored
Fix ASan buffer overflow errors caused by memcmp (#393)
This commit replaces more instances of memcmp with strncmp to fix some more heap-buffer-overflow errors in ASan, some of which can occur when running the regression tests with xtrace enabled. It combines two existing patches plus another fix in name.c for xtrace: https://www.mail-archive.com/ast-developers@lists.research.att.com/msg00877.html https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/035-CR7036535.patch
1 parent d11d4c7 commit d40d998

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/cmd/ksh93/sh/name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Namval_t *nv_addnode(Namval_t* np, int remove)
192192
{
193193
name = (sp->nodes[0])->nvname;
194194
i = strlen(name);
195-
if(memcmp(np->nvname,name,i))
195+
if(strncmp(np->nvname,name,i))
196196
return(np);
197197
}
198198
if(sp->rp && sp->numnodes)

src/cmd/ksh93/sh/nvtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static char **genvalue(char **argv, const char *prefix, int n, struct Walk *wp)
860860
continue;
861861
break;
862862
}
863-
else if(outfile && !wp->nofollow && argv[1] && memcmp(arg,argv[1],l=strlen(arg))==0 && argv[1][l]=='[')
863+
else if(outfile && !wp->nofollow && argv[1] && strncmp(arg,argv[1],l=strlen(arg))==0 && argv[1][l]=='[')
864864
{
865865
int k=1;
866866
Namarr_t *ap=0;

src/cmd/ksh93/sh/nvtype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
10531053
np->nvenv = 0;
10541054
}
10551055
nq->nvname = cp;
1056-
if(name && memcmp(name,&np->nvname[m],n)==0 && np->nvname[m+n]=='.')
1056+
if(name && strncmp(name,&np->nvname[m],n)==0 && np->nvname[m+n]=='.')
10571057
offset -= sizeof(char*);
10581058
dsize = nv_datasize(np,&offset);
10591059
cp = strcopy(name=cp, &np->nvname[m]);

src/cmd/ksh93/sh/path.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ static Pathcomp_t *path_addcomp(Shell_t *shp,Pathcomp_t *first, Pathcomp_t *old,
15261526
len = strlen(name);
15271527
for(pp=first; pp; pp=pp->next)
15281528
{
1529-
if(len == pp->len && memcmp(name,pp->name,len)==0)
1529+
if(len == pp->len && strncmp(name,pp->name,len)==0)
15301530
{
15311531
pp->flags |= flag;
15321532
return(first);
@@ -1817,7 +1817,7 @@ Pathcomp_t *path_dirfind(Pathcomp_t *first,const char *name,int c)
18171817
register Pathcomp_t *pp=first;
18181818
while(pp)
18191819
{
1820-
if(memcmp(name,pp->name,pp->len)==0 && name[pp->len]==c)
1820+
if(strncmp(name,pp->name,pp->len)==0 && name[pp->len]==c)
18211821
return(pp);
18221822
pp = pp->next;
18231823
}

0 commit comments

Comments
 (0)