Skip to contentSkip to conversation

buffer overflow detected ***: dup201 terminated

PATCH New frequent 2 participants 3 messages Sep 10, 2019 – Sep 11, 2019

lore
Share & tools
lore

frequent

author
#0 lore raw

PATCH 1/1 buffer overflow detected ***: dup201 terminated

Issues related to this mail: https://github.com/linux-test-project/ltp/issues/570

According to the bactrace in the issue description, we could easily find out that the problem is due to the codes in dup201.c line 80 and 142. As metan-cuw commented, the loop at line 142 is of no use and probablely is a leftover. So we could safely remove these codes.

This patch does :
1). remove the leftover, and of course, the issue 570 will be eventually go over. 2). removed unused global variables.

The patch goes as:

testcases/kernel/syscalls/dup2/dup201.c +0 -3
index 4507ac1..762ad86 100644
@@ -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;
@@ -86,22 +83,19 @@ struct test_case_t {
        void (*setupfunc) ();
 } TC[] = {
        /* First fd argument is less than 0 - EBADF */

- {
- &badfd, &goodfd, EBADF, NULL},
- /* First fd argument is getdtablesize() - EBADF */
- {
- &maxfd, &goodfd, EBADF, NULL},
- /* Second fd argument is less than 0 - EBADF */
- {
- &mystdout, &badfd, EBADF, NULL},
- /* Second fd argument is getdtablesize() - EBADF */
- {
-&mystdout, &maxfd, EBADF, NULL},};

+       {&badfd, &goodfd, EBADF, NULL},
+       /* First fd argument is getdtablesize() - EBADF */
+       {&maxfd, &goodfd, EBADF, NULL},
+       /* Second fd argument is less than 0 - EBADF */
+       {&mystdout, &badfd, EBADF, NULL},
+       /* Second fd argument is getdtablesize() - EBADF */
+       {&mystdout, &maxfd, EBADF, NULL},

+};

int main(int ac, char **av)

 {
        int lc;

- int i, j;
+ int i;

        tst_parse_opts(ac, av, NULL, NULL);

@@ -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();

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

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

- mypid = getpid();
}

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

        tst_rmdir();

}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190910/35edc0c8/attachment.htm>

#1 lore raw

PATCH 1/1 buffer overflow detected ***: dup201 terminated

Hi!

Quoted 1 line

Issues related to this mail: https://github.com/linux-test-project/ltp/issues/570

You can just add "fixes: #570" instead somewhere in the patch text which will close the issue automatically if the patch is included in the repository.

Quoted 8 lines

According to the bactrace in the issue description, we could easily find out that the problem is due to the codes in dup201.c line 80 and 142. As metan-cuw commented, the loop at line 142 is of no use and probablely is a leftover. So we could safely remove these codes.

This patch does :
1). remove the leftover, and of course, the issue 570 will be eventually go over. 2). removed unused global variables.

The patch goes as:

^
This is unnecessary.

And you are missing the signed-off-by line here, see:

https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

Quoted 75 lines
testcases/kernel/syscalls/dup2/dup201.c +0 -3
index 4507ac1..762ad86 100644
@@ -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;
testcases/kernel/syscalls/dup2/dup201.c +9 -12
@@ -86,22 +83,19 @@ struct test_case_t {
        void (*setupfunc) ();
 } TC[] = {
        /* First fd argument is less than 0 - EBADF */
-       {
-       &badfd, &goodfd, EBADF, NULL},
-           /* First fd argument is getdtablesize() - EBADF */
-       {
-       &maxfd, &goodfd, EBADF, NULL},
-           /* Second fd argument is less than 0 - EBADF */
-       {
-       &mystdout, &badfd, EBADF, NULL},
-           /* Second fd argument is getdtablesize() - EBADF */
-       {
-&mystdout, &maxfd, EBADF, NULL},};
+       {&badfd, &goodfd, EBADF, NULL},
+       /* First fd argument is getdtablesize() - EBADF */
+       {&maxfd, &goodfd, EBADF, NULL},
+       /* Second fd argument is less than 0 - EBADF */
+       {&mystdout, &badfd, EBADF, NULL},
+       /* Second fd argument is getdtablesize() - EBADF */
+       {&mystdout, &maxfd, EBADF, NULL},
+};
 
 
 int main(int ac, char **av)
 {
        int lc;
-       int i, j;
+       int i;
 
 
        tst_parse_opts(ac, av, NULL, NULL);
testcases/kernel/syscalls/dup2/dup201.c +0 -7
@@ -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();
 
@@ -163,7 +151,6 @@ void setup(void)
 
 
        /* get some test specific values */
        maxfd = getdtablesize();
-       mypid = getpid();
 }
 

/*

testcases/kernel/syscalls/dup2/dup201.c void setup(void) · line 163

Quoted 6 lines
testcases/kernel/syscalls/dup2/dup201.c +0 -1
@@ -172,6 +159,5 @@ void setup(void)
  */
 void cleanup(void)
 {
-
        tst_rmdir();
 }

Otherwise the patch looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 buffer overflow detected ***: dup201 terminated

Thank you for the detailed instruction, this is the my first time to submit a patch. Not familiar with the format. And thanks again.

Quoted 109 lines · Cyril Hrubis

Hi!

Quoted 1 line

Issues related to this mail: https://github.com/linux-test-project/ltp/issues/570

You can just add "fixes: #570" instead somewhere in the patch text which will close the issue automatically if the patch is included in the repository.

Quoted 8 lines

According to the bactrace in the issue description, we could easily find out that the problem is due to the codes in dup201.c line 80 and 142. As metan-cuw commented, the loop at line 142 is of no use and probablely is a leftover. So we could safely remove these codes.

This patch does :
1). remove the leftover, and of course, the issue 570 will be eventually go over. 2). removed unused global variables.

The patch goes as:

^
This is unnecessary.

And you are missing the signed-off-by line here, see:

https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#developer-s-certificate-of-origin-1-1

Quoted 75 lines
testcases/kernel/syscalls/dup2/dup201.c +0 -3
index 4507ac1..762ad86 100644
@@ -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;
testcases/kernel/syscalls/dup2/dup201.c +9 -12
@@ -86,22 +83,19 @@ struct test_case_t {
        void (*setupfunc) ();
 } TC[] = {
        /* First fd argument is less than 0 - EBADF */
-       {
-       &badfd, &goodfd, EBADF, NULL},
-           /* First fd argument is getdtablesize() - EBADF */
-       {
-       &maxfd, &goodfd, EBADF, NULL},
-           /* Second fd argument is less than 0 - EBADF */
-       {
-       &mystdout, &badfd, EBADF, NULL},
-           /* Second fd argument is getdtablesize() - EBADF */
-       {
-&mystdout, &maxfd, EBADF, NULL},};
+       {&badfd, &goodfd, EBADF, NULL},
+       /* First fd argument is getdtablesize() - EBADF */
+       {&maxfd, &goodfd, EBADF, NULL},
+       /* Second fd argument is less than 0 - EBADF */
+       {&mystdout, &badfd, EBADF, NULL},
+       /* Second fd argument is getdtablesize() - EBADF */
+       {&mystdout, &maxfd, EBADF, NULL},
+};
 
 
 int main(int ac, char **av)
 {
        int lc;
-       int i, j;
+       int i;
 
 
        tst_parse_opts(ac, av, NULL, NULL);
testcases/kernel/syscalls/dup2/dup201.c +0 -7
@@ -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();
 
@@ -163,7 +151,6 @@ void setup(void)
 
 
        /* get some test specific values */
        maxfd = getdtablesize();
-       mypid = getpid();
 }
 

/*

testcases/kernel/syscalls/dup2/dup201.c void setup(void) · line 163

Quoted 6 lines
testcases/kernel/syscalls/dup2/dup201.c +0 -1
@@ -172,6 +159,5 @@ void setup(void)
  */
 void cleanup(void)
 {
-
        tst_rmdir();
 }

Otherwise the patch looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]