[hackers][sbase][ed] small changes
diff --git a/ed.c b/ed.c index 184ed30..c7648eb 100644 --- a/ed.c +++ b/ed.c @@ -316,7 +316,7 @@ inject(char *s) } static void -clearbuf() +clearbuf(void) { if (scratch) close(scratch); @@ -328,7 +328,7 @@ clearbuf() } static void -setscratch() +setscratch(void) { int r, k; char *dir; @@ -407,7 +407,7 @@ match(int num) } static int -rematch(int num) +rematch(void) { regoff_t off = matchs[0].rm_eo; @@ -451,18 +451,14 @@ getnum(void) for (ln = 0; isdigit(c = input()); ln += n) { if (ln > INT_MAX/10) - goto invalid; + error("invalid address"); n = c - '0'; ln *= 10; if (INT_MAX - ln < n) - goto invalid; + error("invalid address"); } back(c); return ln; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static int @@ -525,7 +521,7 @@ address(int *line) num = isdigit(back(input())) ? getnum() : 1; num *= sign; if (INT_MAX - ln < num) - goto invalid; + error("invalid address"); ln += num; } back(c); @@ -534,14 +530,10 @@ address(int *line) error("invalid address"); *line = ln; return 1; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static void -getlst() +getlst(void) { int ln, c; @@ -589,7 +581,7 @@ deflines(int def1, int def2) } static void -dowrite(char *fname, int trunc) +dowrite(const char *fname, int trunc) { FILE *fp; int i, line; @@ -604,13 +596,13 @@ dowrite(char *fname, int trunc) curln = line2; if (fclose(fp)) error("input/output error"); - strcpy(savfname, fname); + estrlcpy(savfname, fname, sizeof(savfname)); modflag = 0; curln = line; } static void -doread(char *fname) +doread(const char *fname) { size_t cnt; ssize_t n; @@ -735,7 +727,7 @@ getfname(char comm) } else { *bp = '\0'; if (savfname[0] == '\0' || comm == 'e' || comm == 'f') - strcpy(savfname, fname); + estrlcpy(savfname, fname, sizeof(savfname)); return fname; } return NULL; /* not reached */ @@ -1010,7 +1002,7 @@ subline(int num, int nth) static size_t siz, cap; i = changed = siz = 0; - for (m = match(num); m; m = rematch(num)) { + for (m = match(num); m; m = rematch()) { addpre(&s, &cap, &siz); changed |= addsub(&s, &cap, &siz, nth, ++i); if (eol || bol) diff --git a/ed.c b/ed.c index 184ed30..c7648eb 100644 --- a/ed.c +++ b/ed.c @@ -316,7 +316,7 @@ inject(char *s) } static void -clearbuf() +clearbuf(void) { if (scratch) close(scratch); @@ -328,7 +328,7 @@ clearbuf() } static void -setscratch() +setscratch(void) { int r, k; char *dir; @@ -407,7 +407,7 @@ match(int num) } static int -rematch(int num) +rematch(void) { regoff_t off = matchs[0].rm_eo; @@ -451,18 +451,14 @@ getnum(void) for (ln = 0; isdigit(c = input()); ln += n) { if (ln > INT_MAX/10) - goto invalid; + error("invalid address"); n = c - '0'; ln *= 10; if (INT_MAX - ln < n) - goto invalid; + error("invalid address"); } back(c); return ln; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static int @@ -525,7 +521,7 @@ address(int *line) num = isdigit(back(input())) ? getnum() : 1; num *= sign; if (INT_MAX - ln < num) - goto invalid; + error("invalid address"); ln += num; } back(c); @@ -534,14 +530,10 @@ address(int *line) error("invalid address"); *line = ln; return 1; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static void -getlst() +getlst(void) { int ln, c; @@ -589,7 +581,7 @@ deflines(int def1, int def2) } static void -dowrite(char *fname, int trunc) +dowrite(const char *fname, int trunc) { FILE *fp; int i, line; @@ -604,13 +596,13 @@ dowrite(char *fname, int trunc) curln = line2; if (fclose(fp)) error("input/output error"); - strcpy(savfname, fname); + estrlcpy(savfname, fname, sizeof(savfname)); modflag = 0; curln = line; } static void -doread(char *fname) +doread(const char *fname) { size_t cnt; ssize_t n; @@ -735,7 +727,7 @@ getfname(char comm) } else { *bp = '\0'; if (savfname[0] == '\0' || comm == 'e' || comm == 'f') - strcpy(savfname, fname); + estrlcpy(savfname, fname, sizeof(savfname)); return fname; } return NULL; /* not reached */ @@ -1010,7 +1002,7 @@ subline(int num, int nth) static size_t siz, cap; i = changed = siz = 0; - for (m = match(num); m; m = rematch(num)) { + for (m = match(num)
Re: [hackers][sbase][ed] small changes
Uhm, sorry about that, but my last patch violates the default ed behavior by using eprintf(), here is the corrected version: diff --git a/ed.c b/ed.c index 184ed30..1e834a6 100644 --- a/ed.c +++ b/ed.c @@ -316,7 +316,7 @@ inject(char *s) } static void -clearbuf() +clearbuf(void) { if (scratch) close(scratch); @@ -328,7 +328,7 @@ clearbuf() } static void -setscratch() +setscratch(void) { int r, k; char *dir; @@ -407,7 +407,7 @@ match(int num) } static int -rematch(int num) +rematch(void) { regoff_t off = matchs[0].rm_eo; @@ -451,18 +451,14 @@ getnum(void) for (ln = 0; isdigit(c = input()); ln += n) { if (ln > INT_MAX/10) - goto invalid; + error("invalid address"); n = c - '0'; ln *= 10; if (INT_MAX - ln < n) - goto invalid; + error("invalid address"); } back(c); return ln; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static int @@ -525,7 +521,7 @@ address(int *line) num = isdigit(back(input())) ? getnum() : 1; num *= sign; if (INT_MAX - ln < num) - goto invalid; + error("invalid address"); ln += num; } back(c); @@ -534,14 +530,10 @@ address(int *line) error("invalid address"); *line = ln; return 1; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static void -getlst() +getlst(void) { int ln, c; @@ -589,7 +581,7 @@ deflines(int def1, int def2) } static void -dowrite(char *fname, int trunc) +dowrite(const char *fname, int trunc) { FILE *fp; int i, line; @@ -604,13 +596,14 @@ dowrite(char *fname, int trunc) curln = line2; if (fclose(fp)) error("input/output error"); - strcpy(savfname, fname); + if (strlcpy(savfname, fname, 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; @@ -734,8 +727,10 @@ getfname(char comm) error("file name too long"); } else { *bp = '\0'; - if (savfname[0] == '\0' || comm == 'e' || comm == 'f') - strcpy(savfname, fname); + if (savfname[0] == '\0' || comm == 'e' || comm == 'f') { + if (strlcpy(savfname, fname, sizeof(savfname))) + error("file name too long"); + } return fname; } return NULL; /* not reached */ @@ -1010,7 +1005,7 @@ subline(int num, int nth) static size_t siz, cap; i = changed = siz = 0; - for (m = match(num); m; m = rematch(num)) { + for (m = match(num); m; m = rematch()) { addpre(&s, &cap, &siz); changed |= addsub(&s, &cap, &siz, nth, ++i); if (eol || bol) diff --git a/ed.c b/ed.c index 184ed30..1e834a6 100644 --- a/ed.c +++ b/ed.c @@ -316,7 +316,7 @@ inject(char *s) } static void -clearbuf() +clearbuf(void) { if (scratch) close(scratch); @@ -328,7 +328,7 @@ clearbuf() } static void -setscratch() +setscratch(void) { int r, k; char *dir; @@ -407,7 +407,7 @@ match(int num) } static int -rematch(int num) +rematch(void) { regoff_t off = matchs[0].rm_eo; @@ -451,18 +451,14 @@ getnum(void) for (ln = 0; isdigit(c = input()); ln += n) { if (ln > INT_MAX/10) - goto invalid; + error("invalid address"); n = c - '0'; ln *= 10; if (INT_MAX - ln < n) - goto invalid; + error("invalid address"); } back(c); return ln; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static int @@ -525,7 +521,7 @@ address(int *line) num = isdigit(back(input())) ? getnum() : 1; num *= sign; if (INT_MAX - ln < num) - goto invalid; + error("invalid address"); ln += num; } back(c); @@ -534,14 +530,10 @@ address(int *line) error("invalid address"); *line = ln; return 1; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static void -getlst() +getlst(void) { int ln, c; @@ -589,7 +581,7 @@ deflines(int def1, int def2) } static void -dowrite(char *fname, int trunc) +dowrite(const char *fname, int trunc) { FILE *fp; int i, line; @@ -604,13 +596,14 @@ dowrite(char *fname, int trunc) curln = line2; if (fclose(fp)) error("input/output error"); - strcpy(savfname, fname); + if (strlcpy(savfname, fname, 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; @@ -734,8 +727,
Re: [hackers][sbase][ed] small changes
O.o, whhops, that was the wrong patch, attached is the correct one. sorry for spamming the list.diff --git a/ed.c b/ed.c index 184ed30..feeab43 100644 --- a/ed.c +++ b/ed.c @@ -316,7 +316,7 @@ inject(char *s) } static void -clearbuf() +clearbuf(void) { if (scratch) close(scratch); @@ -328,7 +328,7 @@ clearbuf() } static void -setscratch() +setscratch(void) { int r, k; char *dir; @@ -407,7 +407,7 @@ match(int num) } static int -rematch(int num) +rematch(void) { regoff_t off = matchs[0].rm_eo; @@ -451,18 +451,14 @@ getnum(void) for (ln = 0; isdigit(c = input()); ln += n) { if (ln > INT_MAX/10) - goto invalid; + error("invalid address"); n = c - '0'; ln *= 10; if (INT_MAX - ln < n) - goto invalid; + error("invalid address"); } back(c); return ln; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static int @@ -525,7 +521,7 @@ address(int *line) num = isdigit(back(input())) ? getnum() : 1; num *= sign; if (INT_MAX - ln < num) - goto invalid; + error("invalid address"); ln += num; } back(c); @@ -534,14 +530,10 @@ address(int *line) error("invalid address"); *line = ln; return 1; - -invalid: - error("invalid address"); - return -1; /* not reached */ } static void -getlst() +getlst(void) { int ln, c; @@ -589,7 +581,7 @@ deflines(int def1, int def2) } static void -dowrite(char *fname, int trunc) +dowrite(const char *fname, int trunc) { FILE *fp; int i, line; @@ -604,13 +596,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; @@ -734,8 +727,10 @@ getfname(char comm) error("file name too long"); } else { *bp = '\0'; - if (savfname[0] == '\0' || comm == 'e' || comm == 'f') - strcpy(savfname, fname); + if (savfname[0] == '\0' || comm == 'e' || comm == 'f') { + if (strlcpy(savfname, fname, sizeof(savfname)) >= sizeof(savfname)) +error("file name too long"); + } return fname; } return NULL; /* not reached */ @@ -1010,7 +1005,7 @@ subline(int num, int nth) static size_t siz, cap; i = changed = siz = 0; - for (m = match(num); m; m = rematch(num)) { + for (m = match(num); m; m = rematch()) { addpre(&s, &cap, &siz); changed |= addsub(&s, &cap, &siz, nth, ++i); if (eol || bol)
Re: [hackers][sbase][ed] small changes
On Fri, 07 Oct 2016 16:32:53 +0300 "Ali H. Fardan" wrote: Hey Ali, > O.o, whhops, that was the wrong patch, attached is the correct one. > sorry for spamming the list. the patch is looking good. Nice work! Cheers Laslo -- Laslo Hunhold
Re: [hackers] [sbase] [patch] ed: standards compliance, manpage, double free and infinite loop fix
On Thu, 6 Oct 2016 11:04:17 + Thomas Mannay wrote: Hey Thomas, > Resubmission of my patchset for ed, albeit much better formatted so > as to ease reading them. thank you very much for your patches! I'll take a look at them Sunday evening and give you some feedback. They already look very good! Cheers Laslo -- Laslo Hunhold
Re: [hackers] [sbase] [patch] ed: standards compliance, manpage, double free and infinite loop fix
On Thu, 6 Oct 2016 11:04:17 + Thomas Mannay wrote: Hey Thomas, > one thing that has caught my attention is the titling of the patches. It is better to use the active form rather than passive form, so my suggestions for renaming would be "ed: newly joined lines are placed correctly" -> "ed: place newly joined lines correctly" "ed: wrote manpage" -> "add a manpage" Feedback on the content will come Sunday evening. Cheers Laslo -- Laslo Hunhold
Re: [hackers] [sbase] [patch] ed: standards compliance, manpage, double free and infinite loop fix
On Fri, Oct 7, 2016, at 09:43, Laslo Hunhold wrote: > one thing that has caught my attention is the titling of the patches. > It is better to use the active form rather than passive form, so my > suggestions for renaming would be > > "ed: newly joined lines are placed correctly" > -> "ed: place newly joined lines correctly" > > "ed: wrote manpage" > -> "add a manpage" These are both active. "wrote" is the past tense and "add" is not, but neither are passive.
[hackers] [ubase] [patch] last: wrote manpage
I took a stab in the dark that the date should be when the utlity was written. Feel free to correct it if it's should be something else. -- Thomas Mannay >From 847899758d53d17eac7465375dd8c86f39dee391 Mon Sep 17 00:00:00 2001 From: Thomas Mannay Date: Sat, 8 Oct 2016 00:19:08 + Subject: [PATCH] Add last(1) manpage --- last.1 | 21 + 1 file changed, 21 insertions(+) create mode 100644 last.1 diff --git a/last.1 b/last.1 new file mode 100644 index 000..a817f15 --- /dev/null +++ b/last.1 @@ -0,0 +1,21 @@ +.Dd October 16th, 2014 +.Dt LAST 1 +.Os ubase +.Sh NAME +.Nm last +.Nd show a listing of users last logged in +.Sh SYNOPSIS +.Nm +.Op Ar user +.Sh DESCRIPTION +.Nm +uses the contents of /var/log/wtmp to print a listing of users last logged +into the system since that file's creation, along with which tty they +used and the time that they logged in at. +.Nm +can accept a username as an argument, in which case it will print out the +corresponding wtmp entries for that user. +.Sh FILES +/var/log/wtmp +.Sh SEE ALSO +.Xr utmp 5 -- 2.10.0