[hackers] [sbase] ed: Use strlcpy() instead of strcpy() and other minor things || Laslo Hunhold
commit e2f886c7e225a38113d3b332a106d176721fa5c3
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Tue Dec 27 13:07:02 2016 +0100
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Tue Dec 27 13:07:02 2016 +0100
ed: Use strlcpy() instead of strcpy() and other minor things
Based on contribution by Ali H. Fardan, thanks!
diff --git a/ed.c b/ed.c
index 17b925b..72248ab 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -322,7 +322,7 @@ inject(char *s, int j)
}
static void
-clearbuf()
+clearbuf(void)
{
if (scratch)
close(scratch);
_AT_@ -334,7 +334,7 @@ clearbuf()
}
static void
-setscratch()
+setscratch(void)
{
int r, k;
char *dir;
_AT_@ -421,6 +421,7 @@ rematch(int num)
lastmatch += off;
return 1;
}
+
return 0;
}
_AT_@ -547,7 +548,7 @@ invalid:
}
static void
-getlst()
+getlst(void)
{
int ln, c;
_AT_@ -595,7 +596,7 @@ deflines(int def1, int def2)
}
static void
-dowrite(char *fname, int trunc)
+dowrite(const char *fname, int trunc)
{
FILE *fp;
int i, line;
_AT_@ -610,13 +611,14 @@ dowrite(char *fname, int trunc)
curln = line2;
if (fclose(fp))
error("input/output error");
- strcpy(savfname, fname);
+ if (strlcpy(savfname, fname, sizeof(savfname)) >= sizeof(savfname))
+ error("file name too long");
modflag = 0;
curln = line;
}
static void
-doread(char *fname)
+doread(const char *fname)
{
size_t cnt;
ssize_t n;
_AT_@ -741,9 +743,11 @@ getfname(char comm)
} else {
*bp = '\0';
if (savfname[0] == '\0' || comm == 'e' || comm == 'f')
- strcpy(savfname, fname);
+ if (strlcpy(savfname, fname, sizeof(savfname)) >= sizeof(savfname))
+ error("file name too long");
return fname;
}
+
return NULL; /* not reached */
}
Received on Tue Dec 27 2016 - 15:04:01 CET
This archive was generated by hypermail 2.3.0
: Tue Dec 27 2016 - 15:13:03 CET