source: rtems/cpukit/libmisc/shell/main_medit.c @ fdcf6c11

4.115
Last change on this file since fdcf6c11 was fdcf6c11, checked in by Joel Sherrill <joel.sherrill@…>, on 02/03/12 at 22:05:50

PR 2001/shell - medit command argument parsing correction

"medit" overran the argument list, choking on the NULL pointer
following the last argument.

Note that "medit" still only does byte-sized accesses, which limits
its usefulness on most systems.

Author: Werner Almesberger <werner@…>
Signed-off-by: Sebastien Bourdeauducq <sebastien@…>

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  MEDIT Shell Command Implmentation
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include <ctype.h>
18#include <stdio.h>
19#include <string.h>
20
21#include <rtems.h>
22#include <rtems/shell.h>
23#include <rtems/stringto.h>
24#include "internal.h"
25
26static int rtems_shell_main_medit(
27  int   argc,
28  char *argv[]
29)
30{
31  unsigned char *pb;
32  void          *tmpp;
33  int            n;
34  int            i;
35
36  if ( argc < 3 ) {
37    fprintf(stderr,"%s: too few arguments\n", argv[0]);
38    return -1;
39  }
40
41  /*
42   *  Convert arguments into numbers
43   */
44  if ( rtems_string_to_pointer(argv[1], &tmpp, NULL) ) {
45    printf( "Address argument (%s) is not a number\n", argv[1] );
46    return -1;
47  }
48  pb = tmpp;
49
50  /*
51   * Now edit the memory
52   */
53  n = 0;
54  for (i=2 ; i<argc ; i++) {
55    unsigned char tmpc;
56
57    if ( rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
58      printf( "Value (%s) is not a number\n", argv[i] );
59      continue;
60    }
61
62    pb[n++] = tmpc;
63  }
64
65  return 0;
66}
67
68rtems_shell_cmd_t rtems_shell_MEDIT_Command = {
69  "medit",                                      /* name */
70  "medit address value1 [value2 ...]",          /* usage */
71  "mem",                                        /* topic */
72  rtems_shell_main_medit,                       /* command */
73  NULL,                                         /* alias */
74  NULL                                          /* next */
75};
Note: See TracBrowser for help on using the repository browser.