summaryrefslogtreecommitdiff
path: root/lib/command.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-11-12 01:06:32 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-11-12 01:06:32 +0000
commit17aca20bfbb9d7e980a04c9b017f87f027901839 (patch)
tree86e31be2464ae41c3125400a161b87d34419d098 /lib/command.h
parent90e9905f07695fd32696f3d543cbe4ed432263b6 (diff)
lib, vtysh: Fix memory leaks, change cmd_element to const
Fix a few memory issues: * Not freeing tab-completions upon input match failure * Invalid write when null-terminating tab-completions * Not freeing argv[] itself in additinon to elements * Use XFREE() instead of free() as appropriate * Not freeing final token of an [option] during parsing Make a few minor changes to CLI internals: * Improve documentation on matching & completion functions * Only make one copy of cmd_token's when building argv, instead of three * Don't make a copy of the matching cmd_element Make one major(ish) change to CLI internals: * Change all pointers to struct cmd_element to const Code outside of the core CLI units should never have an occasion to modify the internal state of the command system. Doing so could easily amount to having a CLI interface that changes during runtime, and could conceivably lead to security issues. Explicitly disallowing this removes any chance of confusion. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.h')
-rw-r--r--lib/command.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/command.h b/lib/command.h
index 51f7f78085..3bcd66468d 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -210,7 +210,7 @@ struct cmd_element
u_char attr; /* Command attributes */
/* handler function for command */
- int (*func) (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
+ int (*func) (const struct cmd_element *, struct vty *, int, struct cmd_token *[]);
};
/* Return value of the commands. */
@@ -245,11 +245,11 @@ struct cmd_element
};
#define DEFUN_CMD_FUNC_DECL(funcname) \
- static int funcname (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
+ static int funcname (const struct cmd_element *, struct vty *, int, struct cmd_token *[]);
#define DEFUN_CMD_FUNC_TEXT(funcname) \
static int funcname \
- (struct cmd_element *self __attribute__ ((unused)), \
+ (const struct cmd_element *self __attribute__ ((unused)), \
struct vty *vty __attribute__ ((unused)), \
int argc __attribute__ ((unused)), \
struct cmd_token *argv[] __attribute__ ((unused)) )
@@ -410,11 +410,11 @@ extern char *cmd_concat_strvec (vector);
extern vector cmd_describe_command (vector, struct vty *, int *status);
extern char **cmd_complete_command (vector, struct vty *, int *status);
extern const char *cmd_prompt (enum node_type);
-extern int command_config_read_one_line (struct vty *vty, struct cmd_element **, int use_config_node);
+extern int command_config_read_one_line (struct vty *vty, const struct cmd_element **, int use_config_node);
extern int config_from_file (struct vty *, FILE *, unsigned int *line_num);
extern enum node_type node_parent (enum node_type);
-extern int cmd_execute_command (vector, struct vty *, struct cmd_element **, int);
-extern int cmd_execute_command_strict (vector, struct vty *, struct cmd_element **);
+extern int cmd_execute_command (vector, struct vty *, const struct cmd_element **, int);
+extern int cmd_execute_command_strict (vector, struct vty *, const struct cmd_element **);
extern void cmd_init (int);
extern void cmd_terminate (void);
@@ -422,7 +422,7 @@ extern void cmd_terminate (void);
void
del_cmd_element(struct cmd_element *);
struct cmd_element *
-copy_cmd_element(struct cmd_element *cmd);
+copy_cmd_element(const struct cmd_element *cmd);
/* memory management for cmd_token */
struct cmd_token *