source: rtems/cpukit/libmisc/monitor/mon-prmisc.c @ d4ec0a2

4.115
Last change on this file since d4ec0a2 was d4ec0a2, checked in by Josh Oguin <josh.oguin@…>, on 11/19/14 at 20:50:45

monitor/mon-prmisc.c: Use puts() not fprintf()

CodeSonar? flagged this as a case where the user could inject a format
string and cause issues. Since we were not printing anything but a
string, just switching to puts() rather than fprintf(stdout,...) was
sufficient to make this code safer.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/*
2 * Print misc stuff for the monitor dump routines
3 * Each routine returns the number of characters it output.
4 *
5 * TODO:
6 */
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include <rtems.h>
13#include <rtems/monitor.h>
14#include <rtems/assoc.h>
15#include <rtems/score/statesimpl.h>
16
17#include <stdio.h>
18#include <ctype.h>
19#include <inttypes.h>
20
21void
22rtems_monitor_separator(void)
23{
24    fprintf(stdout,"------------------------------------------------------------------------------\n");
25}
26
27uint32_t
28rtems_monitor_pad(
29    uint32_t    destination_column,
30    uint32_t    current_column
31)
32{
33    int pad_length;
34
35    if (destination_column <= current_column)
36        pad_length = 1;
37    else
38        pad_length = destination_column - current_column;
39
40    return fprintf(stdout,"%*s", pad_length, "");
41}
42
43int
44rtems_monitor_dump_decimal(uint32_t   num)
45{
46    return fprintf(stdout,"%4" PRId32, num);
47}
48
49int
50rtems_monitor_dump_addr(void *addr)
51{
52    return fprintf(stdout,"0x%p", addr);
53}
54
55int
56rtems_monitor_dump_hex(uint32_t   num)
57{
58    return fprintf(stdout,"0x%" PRIx32, num);
59}
60
61static int
62rtems_monitor_dump_assoc_bitfield(
63    const rtems_assoc_t *ap,
64    const char          *separator,
65    uint32_t             value
66  )
67{
68    uint32_t   b;
69    uint32_t   length = 0;
70    const char *name;
71
72    for (b = 1; b; b <<= 1)
73        if (b & value)
74        {
75            if (length)
76                length += fprintf(stdout,"%s", separator);
77
78            name = rtems_assoc_name_by_local(ap, b);
79
80            if (name)
81                length += fprintf(stdout,"%s", name);
82            else
83                length += fprintf(stdout,"0x%" PRIx32, b);
84        }
85
86    return length;
87}
88
89int
90rtems_monitor_dump_id(rtems_id id)
91{
92#if defined(RTEMS_USE_16_BIT_OBJECT)
93    return fprintf(stdout,"%08" PRIx16, id);
94#else
95    return fprintf(stdout,"%08" PRIx32, id);
96#endif
97}
98
99int
100rtems_monitor_dump_name(rtems_id id)
101{
102    char name_buffer[18] = "????";
103
104    rtems_object_get_name( id, sizeof(name_buffer), name_buffer );
105
106    return puts( name_buffer );
107}
108
109int
110rtems_monitor_dump_priority(rtems_task_priority priority)
111{
112    return fprintf(stdout,"%3" PRId32, priority);
113}
114
115
116static const rtems_assoc_t rtems_monitor_state_assoc[] = {
117    { "DORM",   STATES_DORMANT, 0 },
118    { "SUSP",   STATES_SUSPENDED, 0 },
119    { "DELAY",  STATES_DELAYING, 0 },
120    { "Wtime",  STATES_WAITING_FOR_TIME, 0 },
121    { "Wbuf",   STATES_WAITING_FOR_BUFFER, 0 },
122    { "Wseg",   STATES_WAITING_FOR_SEGMENT, 0 },
123    { "Wmsg" ,  STATES_WAITING_FOR_MESSAGE, 0 },
124    { "Wevnt",  STATES_WAITING_FOR_EVENT, 0 },
125    { "Wsysev", STATES_WAITING_FOR_SYSTEM_EVENT, 0 },
126    { "Wsem",   STATES_WAITING_FOR_SEMAPHORE, 0 },
127    { "Wmutex", STATES_WAITING_FOR_MUTEX, 0 },
128    { "Wcvar",  STATES_WAITING_FOR_CONDITION_VARIABLE, 0 },
129    { "Wjatx",  STATES_WAITING_FOR_JOIN_AT_EXIT, 0 },
130    { "Wrpc",   STATES_WAITING_FOR_RPC_REPLY, 0 },
131    { "WRATE",  STATES_WAITING_FOR_PERIOD, 0 },
132    { "Wsig",   STATES_WAITING_FOR_SIGNAL, 0 },
133    { "Wbar",   STATES_WAITING_FOR_BARRIER, 0 },
134    { "Wrwlk",  STATES_WAITING_FOR_RWLOCK, 0 },
135    { "Wisig",  STATES_INTERRUPTIBLE_BY_SIGNAL, 0 },
136    { "Wwkup",  STATES_WAITING_FOR_BSD_WAKEUP, 0 },
137    { "Wterm",  STATES_WAITING_FOR_TERMINATION, 0 },
138    { "ZOMBI",  STATES_ZOMBIE, 0 },
139    { "MIGRA",  STATES_MIGRATING, 0 },
140    { "RESTA",  STATES_RESTARTING, 0 },
141    { 0, 0, 0 },
142};
143
144int
145rtems_monitor_dump_state(States_Control state)
146{
147    int   length = 0;
148
149    if (state == STATES_READY)  /* assoc doesn't deal with this as it is 0 */
150        length += fprintf(stdout,"READY");
151
152    length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_state_assoc,
153                                                ":",
154                                                state);
155    return length;
156}
157
158static const rtems_assoc_t rtems_monitor_attribute_assoc[] = {
159    { "GL",  RTEMS_GLOBAL, 0 },
160    { "PR",  RTEMS_PRIORITY, 0 },
161    { "FL",  RTEMS_FLOATING_POINT, 0 },
162    { "BI",  RTEMS_BINARY_SEMAPHORE, 0 },
163    { "SB",  RTEMS_SIMPLE_BINARY_SEMAPHORE, 0 },
164    { "IN",  RTEMS_INHERIT_PRIORITY, 0 },
165    { "CE",  RTEMS_PRIORITY_CEILING, 0 },
166    { "AR",  RTEMS_BARRIER_AUTOMATIC_RELEASE, 0 },
167    { "ST",  RTEMS_SYSTEM_TASK, 0 },
168    { 0, 0, 0 },
169};
170
171int
172rtems_monitor_dump_attributes(rtems_attribute attributes)
173{
174    int   length = 0;
175
176    if (attributes == RTEMS_DEFAULT_ATTRIBUTES)  /* value is 0 */
177        length += fprintf(stdout,"DEFAULT");
178
179    length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_attribute_assoc,
180                                                ":",
181                                                attributes);
182    return length;
183}
184
185static const rtems_assoc_t rtems_monitor_modes_assoc[] = {
186    { "nP",     RTEMS_NO_PREEMPT, 0 },
187    { "T",      RTEMS_TIMESLICE, 0 },
188    { "nA",     RTEMS_NO_ASR, 0 },
189    { 0, 0, 0 },
190};
191
192int
193rtems_monitor_dump_modes(rtems_mode modes)
194{
195    uint32_t   length = 0;
196
197    if (modes == RTEMS_DEFAULT_MODES)  /* value is 0 */
198        length += fprintf(stdout,"P:T:nA");
199
200    length += rtems_monitor_dump_assoc_bitfield(rtems_monitor_modes_assoc,
201                                                ":",
202                                                modes);
203    return length;
204}
205
206static const rtems_assoc_t rtems_monitor_events_assoc[] = {
207    { "0",   RTEMS_EVENT_0, 0 },
208    { "1",   RTEMS_EVENT_1, 0 },
209    { "2",   RTEMS_EVENT_2, 0 },
210    { "3",   RTEMS_EVENT_3, 0 },
211    { "4",   RTEMS_EVENT_4, 0 },
212    { "5",   RTEMS_EVENT_5, 0 },
213    { "6",   RTEMS_EVENT_6, 0 },
214    { "7",   RTEMS_EVENT_7, 0 },
215    { "8",   RTEMS_EVENT_8, 0 },
216    { "9",   RTEMS_EVENT_9, 0 },
217    { "10",  RTEMS_EVENT_10, 0 },
218    { "11",  RTEMS_EVENT_11, 0 },
219    { "12",  RTEMS_EVENT_12, 0 },
220    { "13",  RTEMS_EVENT_13, 0 },
221    { "14",  RTEMS_EVENT_14, 0 },
222    { "15",  RTEMS_EVENT_15, 0 },
223    { "16",  RTEMS_EVENT_16, 0 },
224    { "17",  RTEMS_EVENT_17, 0 },
225    { "18",  RTEMS_EVENT_18, 0 },
226    { "19",  RTEMS_EVENT_19, 0 },
227    { "20",  RTEMS_EVENT_20, 0 },
228    { "21",  RTEMS_EVENT_21, 0 },
229    { "22",  RTEMS_EVENT_22, 0 },
230    { "23",  RTEMS_EVENT_23, 0 },
231    { "24",  RTEMS_EVENT_24, 0 },
232    { "25",  RTEMS_EVENT_25, 0 },
233    { "26",  RTEMS_EVENT_26, 0 },
234    { "27",  RTEMS_EVENT_27, 0 },
235    { "28",  RTEMS_EVENT_28, 0 },
236    { "29",  RTEMS_EVENT_29, 0 },
237    { "30",  RTEMS_EVENT_30, 0 },
238    { "31",  RTEMS_EVENT_31, 0 },
239    { 0, 0, 0 },
240};
241
242int
243rtems_monitor_dump_events(rtems_event_set events)
244{
245    if (events == 0)
246        return fprintf(stdout,"  NONE  ");
247
248    return fprintf(stdout,"%08" PRIx32, events);
249}
250
251int
252rtems_monitor_dump_notepad(uint32_t   *notepad)
253{
254    int   length = 0;
255    int i;
256
257    for (i=0; i < RTEMS_NUMBER_NOTEPADS; i++)
258        if (notepad[i])
259            length += fprintf(stdout,"%d: 0x%" PRIx32, i, notepad[i]);
260
261    return length;
262}
Note: See TracBrowser for help on using the repository browser.