source: rtems/testsuites/libtests/top/task1.c @ 5700d8ba

5
Last change on this file since 5700d8ba was 5700d8ba, checked in by Joel Sherrill <joel@…>, on 06/12/17 at 02:05:42

top/task1.c: Fix sprintf() buffer overflow

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/*  Task_1
2 *
3 *  This test serves as a test task.  It creates and deletes
4 *  the remaining tasks, twice so that the tasks displayed by
5 *  the top command grow past the max tasks displayed then shrink
6 *  back down.
7 *
8 *  Input parameters:
9 *    argument - task argument
10 *
11 *  Output parameters:  NONE
12 *
13 *  COPYRIGHT (c) 2014.
14 *  On-Line Applications Research Corporation (OAR).
15 *
16 *  The license and distribution terms for this file may be
17 *  found in the file LICENSE in this distribution or at
18 *  http://www.rtems.org/license/LICENSE.
19 */
20
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include "system.h"
26
27static void create_and_start( uint32_t i )
28{
29  rtems_status_code status;
30  char              str[30];
31  char              name[6];
32
33  sprintf(name, "TA%02" PRId32 " ", i);
34
35  Task_name[ i ] =  rtems_build_name(
36    name[0], name[1], name[2], name[3]
37  );
38
39  status = rtems_task_create(
40    Task_name[ i ],
41    1,
42    RTEMS_MINIMUM_STACK_SIZE,
43    RTEMS_TIMESLICE,
44    RTEMS_FLOATING_POINT,
45    &Task_id[ i ]
46  );
47  sprintf(str,"rtems_task_create of %s", name);
48  directive_failed( status, str );
49
50  status = rtems_task_start( Task_id[ i ], Task_3, i );
51  sprintf(str, "rtems_task_start of %s", name);
52  directive_failed( status, str);
53}
54
55rtems_task Task_1(
56  rtems_task_argument argument
57)
58{
59  rtems_status_code status;
60  char              str[80];
61  uint32_t          i,j;
62
63  for(j=0; j<2; j++) {
64
65    for( i=3; i<TASK_COUNT; i++) {
66      create_and_start(i);
67      status = rtems_task_wake_after (TicksPerSecond * 5);
68      directive_failed( status, "rtems_task_wake_after" );
69    }
70
71    status = rtems_task_wake_after (TicksPerSecond * 10);
72    directive_failed( status, "rtems_task_wake_after" );
73
74    for( i=3; i<TASK_COUNT; i++) {
75      status = rtems_task_delete( Task_id[i] );
76      sprintf(str, "task delete TA%02" PRId32 "", i);
77      directive_failed( status, str );
78      status = rtems_task_wake_after (TicksPerSecond * 5);
79      directive_failed( status, "rtems_task_wake_after" );
80    }
81  }
82
83  TEST_END();
84  rtems_test_exit( 0 );
85}
Note: See TracBrowser for help on using the repository browser.