Changeset eb961961 in rtems


Ignore:
Timestamp:
Dec 19, 2008, 2:59:35 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
51a6fd5
Parents:
52410c2
Message:

2008-12-19 Sebastian Huber <sebastian.huber@…>

  • libblock/src/ide_part_table.c: Fixed NULL pointer access.
  • libmisc/monitor/mon-command.c, libmisc/monitor/mon-editor.c, libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h, libmisc/shell/cmds.c: The list of registered monitor commands is now private and only accessible via a lookup and iterate function.
Location:
cpukit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r52410c2 reb961961  
     12008-12-19      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * libblock/src/ide_part_table.c: Fixed NULL pointer access.
     4        * libmisc/monitor/mon-command.c, libmisc/monitor/mon-editor.c,
     5        libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h,
     6        libmisc/shell/cmds.c: The list of registered monitor commands is now
     7        private and only accessible via a lookup and iterate function.
     8
    192008-12-18      Joel Sherrill <joel.sherrill@oarcorp.com>
    210
  • cpukit/libblock/src/ide_part_table.c

    r52410c2 reb961961  
    377377         part_num++)
    378378    {
    379         if (is_extended(disk_desc->partitions[part_num]->sys_type))
    380         {
    381             read_extended_partition(disk_desc->partitions[part_num]->start,
    382                                     disk_desc->partitions[part_num]);
     379        part_desc = disk_desc->partitions[part_num];
     380        if (part_desc != NULL && is_extended(part_desc->sys_type))
     381        {
     382            read_extended_partition(part_desc->start, part_desc);
    383383        }
    384384    }
  • cpukit/libmisc/monitor/mon-command.c

    r52410c2 reb961961  
    2424#include <rtems.h>
    2525#include <rtems/monitor.h>
    26 
    27 /*
    28  * Look up a command in a command table
    29  *
    30  */
    31 
    32 const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
    33   const rtems_monitor_command_entry_t *table,
    34   const char *command_name
    35 )
    36 {
    37   const rtems_monitor_command_entry_t *found_it = NULL;
    38   size_t command_length = 0;
    39 
    40   if (command_name == NULL) {
    41     return NULL;
    42   }
    43 
    44   command_length = strlen(command_name);
    45 
    46   while (table != NULL) {
    47     if (table->command != NULL) {
    48       /* Check for ambiguity */
    49       if (!strncmp(table->command, command_name, command_length)) {
    50         if (found_it == NULL) {
    51           found_it = table;
    52         } else {
    53           return NULL;
    54         }
    55       }
    56     }
    57     table = table->next;
    58   }
    59 
    60   /* No ambiguity (the possible partial command was unique after all) */
    61 
    62   /* Ignore empty commands */
    63   if (found_it == NULL || found_it->command_function == NULL) {
    64     return NULL;
    65   }
    66 
    67   return found_it;
    68 }
    6926
    7027static void
     
    174131  if (command_name && (*command_name != '\0'))
    175132  {
    176     command = rtems_monitor_command_lookup (table, command_name);
     133    command = rtems_monitor_command_lookup (command_name);
    177134
    178135    if (command)
     
    232189  }
    233190}
     191
     192typedef struct {
     193  const char *name;
     194  size_t length;
     195  const rtems_monitor_command_entry_t *match;
     196} rtems_monitor_command_lookup_entry;
     197
     198static bool rtems_monitor_command_lookup_routine(
     199  const rtems_monitor_command_entry_t *e,
     200  void *arg
     201)
     202{
     203  rtems_monitor_command_lookup_entry *le =
     204    (rtems_monitor_command_lookup_entry *) arg;
     205
     206  /* Check name */
     207  if (strncmp(e->command, le->name, le->length) == 0) {
     208    /* Check for ambiguity */
     209    if (le->match == NULL) {
     210      le->match = e;
     211    } else {
     212      return false;
     213    }
     214  }
     215
     216  return true;
     217}
     218
     219/**
     220 * @brief Looks for a command with the name @a name in the list of registered
     221 * commands.
     222 *
     223 * The parameter @a name must not be NULL.
     224 *
     225 * Returns the corresponding command entry or NULL if no command is found.
     226 */
     227const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
     228  const char *name
     229)
     230{
     231  rtems_monitor_command_lookup_entry e = {
     232    .name = name,
     233    .length = strlen( name),
     234    .match = NULL
     235  };
     236
     237  rtems_monitor_command_iterate(rtems_monitor_command_lookup_routine, &e);
     238
     239  return e.match;
     240}
  • cpukit/libmisc/monitor/mon-editor.c

    r52410c2 reb961961  
    598598            continue;
    599599        if (argc < 1
    600           || (command = rtems_monitor_command_lookup(rtems_monitor_commands,
    601                                                      argv [0])) == 0)
    602         {
    603             /* no command */
    604             fprintf(stdout,"Unrecognised command; try 'help'\n");
    605             continue;
     600          || (command = rtems_monitor_command_lookup(argv [0])) == 0) {
     601          /* no command */
     602          fprintf(stdout,"Unrecognised command; try 'help'\n");
     603          continue;
    606604        }
    607605
  • cpukit/libmisc/monitor/mon-monitor.c

    r52410c2 reb961961  
    6161 */
    6262
    63 const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
     63static const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
    6464    { "config",
    6565      "Show the system configuration.",
     
    481481  return 1;
    482482}
     483
     484/**
     485 * @brief Iterates through all registerd commands.
     486 *
     487 * For each command the interation routine @a routine is called with the
     488 * command entry and the user provided argument @a arg.  It is guaranteed that
     489 * the command name and function are not NULL.
     490 */
     491void rtems_monitor_command_iterate(
     492  rtems_monitor_per_command_routine routine,
     493  void *arg
     494)
     495{
     496  const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
     497
     498  while (e != NULL) {
     499    if (e->command != NULL && e->command_function != NULL) {
     500      if (!routine(e, arg)) {
     501        break;
     502      }
     503    }
     504    e = e->next;
     505  }
     506}
  • cpukit/libmisc/monitor/monitor.h

    r52410c2 reb961961  
    369369} rtems_monitor_object_info_t;
    370370
     371typedef bool (*rtems_monitor_per_command_routine)(const rtems_monitor_command_entry_t *, void *);
    371372
    372373/* monitor.c */
     
    378379void    rtems_monitor_symbols_loadup(void);
    379380int     rtems_monitor_insert_cmd(rtems_monitor_command_entry_t *);
    380 int     rtems_monitor_erase_cmd(rtems_monitor_command_entry_t *);
    381381void    rtems_monitor_wakeup(void);
     382void rtems_monitor_command_iterate(rtems_monitor_per_command_routine routine, void *arg);
    382383rtems_status_code rtems_monitor_suspend(rtems_interval timeout);
    383384
     
    396397int     rtems_monitor_make_argv(char *, int *, char **);
    397398int     rtems_monitor_command_read(char *, int *, char **);
    398 const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const rtems_monitor_command_entry_t *table, const char *command_name);
    399399void    rtems_monitor_command_usage(const rtems_monitor_command_entry_t *, const char *);
    400400void    rtems_monitor_help_cmd(int, char **, const rtems_monitor_command_arg_t *, bool);
     401const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const char *name);
    401402
    402403/* prmisc.c */
     
    520521extern rtems_symbol_table_t *rtems_monitor_symbols;
    521522
    522 /* FIXME: This should not be here */
    523 extern const rtems_monitor_command_entry_t rtems_monitor_commands[];
    524 
    525523#define MONITOR_WAKEUP_EVENT   RTEMS_EVENT_0
    526524
  • cpukit/libmisc/shell/cmds.c

    r52410c2 reb961961  
    3737  }
    3838
    39   command = rtems_monitor_command_lookup(rtems_monitor_commands, argv [0]);
     39  command = rtems_monitor_command_lookup(argv [0]);
    4040
    4141  if (command == NULL) {
     
    4848}
    4949
     50static bool rtems_shell_register_command(const rtems_monitor_command_entry_t *e, void *arg)
     51{
     52  /* Exclude EXIT (alias quit)*/
     53  if (strcmp("exit", e->command) != 0) {
     54    rtems_shell_cmd_t *shell_cmd =
     55      (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
     56   
     57    if (shell_cmd != NULL) {
     58      shell_cmd->name    = e->command;
     59      shell_cmd->topic   = "monitor";
     60      shell_cmd->usage   = e->usage;
     61      shell_cmd->command = rtems_shell_main_monitor;
     62      shell_cmd->alias   = NULL;
     63      shell_cmd->next    = NULL;
     64   
     65      if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
     66        free(shell_cmd);
     67      }
     68    }
     69  }
     70
     71  return true;
     72}
     73
    5074void rtems_shell_register_monitor_commands(void)
    5175{
    52   /* Monitor topic */
    53   const rtems_monitor_command_entry_t *e = rtems_monitor_commands;
    54 
    55   while (e != NULL) {
    56     /* Exclude EXIT (alias quit)*/
    57     if (e->command != NULL && strcmp("exit", e->command) != 0) {
    58       rtems_shell_cmd_t *shell_cmd =
    59         (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
    60      
    61       if (shell_cmd != NULL) {
    62         shell_cmd->name    = e->command;
    63         shell_cmd->topic   = "monitor";
    64         shell_cmd->usage   = e->usage;
    65         shell_cmd->command = rtems_shell_main_monitor;
    66         shell_cmd->alias   = NULL;
    67         shell_cmd->next    = NULL;
    68      
    69         if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
    70           free(shell_cmd);
    71         }
    72       }
    73     }
    74     e = e->next;
    75   }
     76  rtems_monitor_command_iterate(rtems_shell_register_command, NULL);
    7677}
Note: See TracChangeset for help on using the changeset viewer.