]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/bug-rewind.c
Bug 20116: Fix use after free in pthread_create()
[thirdparty/glibc.git] / libio / bug-rewind.c
CommitLineData
706d1dee
UD
1#include <stdio.h>
2#include <wchar.h>
3
4#define PASSED 0
5#define FAILED 3
6
7
442685a8
UD
8static int fd;
9
10static void prepare (void);
11#define PREPARE(argc, argv) prepare ()
12
13
3fa3d0b2
UD
14#define TEST_FUNCTION do_test ()
15static int do_test (void);
16#include "../test-skeleton.c"
17
18
442685a8
UD
19static void
20prepare (void)
21{
22 fd = create_temp_file ("wrewind.", NULL);
23 if (fd == -1)
24 exit (3);
25}
26
27
3fa3d0b2
UD
28static int
29do_test (void)
706d1dee
UD
30{
31 FILE *fptr;
32 char arg1;
33 char arg2;
3fa3d0b2 34 int ret1, ret2, result, num;
706d1dee
UD
35
36 ret1 = 0;
37 ret2 = 0;
38
3fa3d0b2
UD
39 fptr = fdopen (fd, "w+");
40 if (fptr == NULL)
706d1dee
UD
41 {
42 printf ("Unable to open file.\n");
43 return 1;
44 }
45
3fa3d0b2 46 if (fwprintf (fptr, L"cderf") <= 0)
706d1dee
UD
47 {
48 printf ("Unable to write to file with fwprintf().\n");
49 fclose (fptr);
50 return 2;
51 }
52
53 rewind (fptr);
54 ret1 = fwscanf (fptr, L"%c%c", &arg1, &arg2);
12da14a5
JM
55 if (ret1 != 2)
56 {
57 printf ("first fwscanf returned %d, expected 2\n", ret1);
58 return 3;
59 }
706d1dee
UD
60
61 rewind (fptr);
62 ret2 = fwscanf (fptr, L"%c%n%c", &arg1, &num, &arg2);
12da14a5
JM
63 if (ret2 != 2)
64 {
65 printf ("second fwscanf returned %d, expected 2\n", ret2);
66 return 4;
67 }
706d1dee
UD
68
69 if (arg2 != 'd')
70 {
71 result = FAILED;
72 printf ("rewind after first fwscanf failed\n");
73 }
74 else
75 {
76 printf ("Passed\n");
77 result = PASSED;
78 }
79
80
81 fclose (fptr);
82 return result;
83}