git.droids-corp.org
/
libcmdline.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
cmdline: check size of result buffer to avoid overflow
[libcmdline.git]
/
src
/
lib
/
cmdline.c
diff --git
a/src/lib/cmdline.c
b/src/lib/cmdline.c
index
6d37885
..
d44e44b
100644
(file)
--- a/
src/lib/cmdline.c
+++ b/
src/lib/cmdline.c
@@
-86,6
+86,8
@@
cmdline_valid_buffer(struct rdline *rdl, const char *buf,
cmdline_printf(cl, "Command not found\n");
else if (ret == CMDLINE_PARSE_BAD_ARGS)
cmdline_printf(cl, "Bad arguments\n");
cmdline_printf(cl, "Command not found\n");
else if (ret == CMDLINE_PARSE_BAD_ARGS)
cmdline_printf(cl, "Bad arguments\n");
+ else if (ret == CMDLINE_PARSE_UNTERMINATED_QUOTE)
+ cmdline_printf(cl, "Unterminated quote\n");
}
static int
}
static int
@@
-97,20
+99,23
@@
cmdline_complete_buffer(struct rdline *rdl, const char *buf,
return cmdline_complete(cl, buf, state, dstbuf, dstsize);
}
return cmdline_complete(cl, buf, state, dstbuf, dstsize);
}
-void
+int
cmdline_write_char(struct rdline *rdl, char c)
{
cmdline_write_char(struct rdline *rdl, char c)
{
+ int ret = -1;
struct cmdline *cl = rdl->opaque;
struct cmdline *cl = rdl->opaque;
- if (cl->s_out >= 0) {
- write(cl->s_out, &c, 1);
- }
+
+ if (cl->s_out >= 0)
+ ret = write(cl->s_out, &c, 1);
+
+ return ret;
}
void
cmdline_set_prompt(struct cmdline *cl, const char *prompt)
{
}
void
cmdline_set_prompt(struct cmdline *cl, const char *prompt)
{
- snprintf(cl->prompt, sizeof(cl->prompt), prompt);
+ snprintf(cl->prompt, sizeof(cl->prompt),
"%s",
prompt);
}
struct cmdline *
}
struct cmdline *
@@
-222,10
+227,9
@@
cmdline_interact(struct cmdline *cl)
c = -1;
while (1) {
c = -1;
while (1) {
- read(cl->s_in, &c, 1);
- if (cmdline_in(cl, &c, 1) < 0) {
+ if (read(cl->s_in, &c, 1) < 0)
+ break;
+ if (cmdline_in(cl, &c, 1) < 0)
break;
break;
- }
}
}
- cmdline_free(cl);
}
}