Skip to content

Commit

Permalink
syscalls/dup201: Fix buffer overflow
Browse files Browse the repository at this point in the history
The code that fills the string in a loop and calls unlink() does not
actually do anything and seems to be leftover, hence we delete it along
with unused variables.

Fixes: linux-test-project#570

Signed-off-by: Wu,Haiqiang <frequentemail@126.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
  • Loading branch information
CentUser authored and jcronenberg committed Nov 26, 2019
1 parent e74afef commit 3dbd369
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions testcases/kernel/syscalls/dup2/dup201.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ int maxfd;
int goodfd = 5;
int badfd = -1;
int mystdout = 0;
int fd, fd1;
int mypid;
char fname[20];

struct test_case_t {
int *ofd;
Expand All @@ -86,22 +83,19 @@ struct test_case_t {
void (*setupfunc) ();
} TC[] = {
/* First fd argument is less than 0 - EBADF */
{
&badfd, &goodfd, EBADF, NULL},
{&badfd, &goodfd, EBADF, NULL},
/* First fd argument is getdtablesize() - EBADF */
{
&maxfd, &goodfd, EBADF, NULL},
{&maxfd, &goodfd, EBADF, NULL},
/* Second fd argument is less than 0 - EBADF */
{
&mystdout, &badfd, EBADF, NULL},
{&mystdout, &badfd, EBADF, NULL},
/* Second fd argument is getdtablesize() - EBADF */
{
&mystdout, &maxfd, EBADF, NULL},};
{&mystdout, &maxfd, EBADF, NULL},
};

int main(int ac, char **av)
{
int lc;
int i, j;
int i;

tst_parse_opts(ac, av, NULL, NULL);

Expand Down Expand Up @@ -137,12 +131,6 @@ int main(int ac, char **av)
strerror(TC[i].error));
}
}
/* cleanup things in case we are looping */
for (j = fd1; j < maxfd; j++) {
sprintf(fname, "dup201.%d.%d", j, mypid);
(void)close(j);
(void)unlink(fname);
}
}
cleanup();

Expand All @@ -163,7 +151,6 @@ void setup(void)

/* get some test specific values */
maxfd = getdtablesize();
mypid = getpid();
}

/*
Expand All @@ -172,6 +159,5 @@ void setup(void)
*/
void cleanup(void)
{

tst_rmdir();
}

0 comments on commit 3dbd369

Please sign in to comment.