summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc
diff options
context:
space:
mode:
authorJoel Sherrill <joel@rtems.org>2019-03-13 10:07:23 -0500
committerJoel Sherrill <joel@rtems.org>2019-03-14 08:21:44 -0500
commitc319945f53a3600488a01ad563b4b6ee2901ebd4 (patch)
treece4c43def02857afd5b4facee58d7177b0f56896 /cpukit/libmisc
parentfifo.c: Eliminate logically dead code (Coverity 1437635) (diff)
downloadrtems-c319945f53a3600488a01ad563b4b6ee2901ebd4.tar.bz2
main_edit.c: Use strncpy() to eliminate potential buffer overflow.
Diffstat (limited to 'cpukit/libmisc')
-rw-r--r--cpukit/libmisc/shell/main_edit.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c
index 079e9ff73d..e43ff68d2b 100644
--- a/cpukit/libmisc/shell/main_edit.c
+++ b/cpukit/libmisc/shell/main_edit.c
@@ -286,7 +286,7 @@ static struct editor *find_editor(struct env *env, char *filename) {
struct editor *ed = env->current;
struct editor *start = ed;
- if (!realpath(filename, fn)) strcpy(fn, filename);
+ if (!realpath(filename, fn)) strncpy(fn, filename, FILENAME_MAX);
do {
if (strcmp(fn, ed->filename) == 0) return ed;
@@ -297,7 +297,7 @@ static struct editor *find_editor(struct env *env, char *filename) {
static int new_file(struct editor *ed, char *filename) {
if (*filename) {
- strcpy(ed->filename, filename);
+ strncpy(ed->filename, filename, FILENAME_MAX);
} else {
sprintf(ed->filename, "Untitled-%d", ++ed->env->untitled);
ed->newfile = 1;
@@ -1752,7 +1752,7 @@ static void read_from_stdin(struct editor *ed) {
insert(ed, pos, (unsigned char*) buffer, n);
pos += n;
}
- strcpy(ed->filename, "<stdin>");
+ strncpy(ed->filename, "<stdin>", FILENAME_MAX);
ed->newfile = 1;
ed->dirty = 0;
}
@@ -1775,7 +1775,8 @@ static void save_editor(struct editor *ed) {
return;
}
}
- strcpy(ed->filename, (const char*) ed->env->linebuf);
+ strncpy(
+ ed->filename, (const char*) ed->env->linebuf, FILENAME_MAX);
ed->newfile = 0;
}