sprintf considered harmful

This commit is contained in:
dholland 2014-03-23 05:06:42 +00:00
parent 1c111fd5cf
commit a3542600fb
9 changed files with 121 additions and 107 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: buf.c,v 1.26 2006/03/17 14:37:14 rumble Exp $ */
/* $NetBSD: buf.c,v 1.27 2014/03/23 05:06:42 dholland Exp $ */
/* buf.c: This file contains the scratch-file buffer routines for the
ed line editor. */
@ -33,7 +33,7 @@
#if 0
static char *rcsid = "@(#)buf.c,v 1.4 1994/02/01 00:34:35 alm Exp";
#else
__RCSID("$NetBSD: buf.c,v 1.26 2006/03/17 14:37:14 rumble Exp $");
__RCSID("$NetBSD: buf.c,v 1.27 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -70,7 +70,7 @@ get_sbuf_line(line_t *lp)
sfseek = lp->seek;
if (fseek(sfp, sfseek, SEEK_SET) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot seek temp file");
seterrmsg("cannot seek temp file");
return NULL;
}
}
@ -78,7 +78,7 @@ get_sbuf_line(line_t *lp)
REALLOC(sfbuf, sfbufsz, len + 1, NULL);
if ((ct = fread(sfbuf, sizeof(char), len, sfp)) < 0 || ct != len) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot read temp file");
seterrmsg("cannot read temp file");
return NULL;
}
sfseek += len; /* update file position */
@ -98,14 +98,14 @@ put_sbuf_line(char *cs)
if ((lp = (line_t *) malloc(sizeof(line_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
return NULL;
}
/* assert: cs is '\n' terminated */
for (s = cs; *s != '\n'; s++)
;
if (s - cs >= LINECHARS) {
sprintf(errmsg, "line too long");
seterrmsg("line too long");
free(lp);
return NULL;
}
@ -114,7 +114,7 @@ put_sbuf_line(char *cs)
if (seek_write) {
if (fseek(sfp, 0L, SEEK_END) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot seek temp file");
seterrmsg("cannot seek temp file");
free(lp);
return NULL;
}
@ -125,7 +125,7 @@ put_sbuf_line(char *cs)
if ((ct = fwrite(cs, sizeof(char), len, sfp)) < 0 || ct != len) {
sfseek = -1;
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot write temp file");
seterrmsg("cannot write temp file");
free(lp);
return NULL;
}
@ -160,7 +160,7 @@ get_line_node_addr(line_t *lp)
while (cp != lp && (cp = cp->q_forw) != &buffer_head)
n++;
if (n && cp == &buffer_head) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
}
return n;
@ -222,7 +222,7 @@ open_sbuf(void)
(void)asprintf(&sfn, "%s/ed.XXXXXX", tmp);
if (sfn == NULL) {
warn(NULL);
sprintf(errmsg, "could not allocate memory");
seterrmsg("could not allocate memory");
umask(u);
return ERR;
}
@ -232,7 +232,7 @@ open_sbuf(void)
if (fd != -1)
close(fd);
warn("%s", sfn);
sprintf(errmsg, "cannot open temp file");
seterrmsg("cannot open temp file");
umask(u);
return ERR;
}
@ -248,7 +248,7 @@ close_sbuf(void)
if (sfp) {
if (fclose(sfp) < 0) {
fprintf(stderr, "%s: %s\n", sfn, strerror(errno));
sprintf(errmsg, "cannot close temp file");
seterrmsg("cannot close temp file");
return ERR;
}
sfp = NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: cbc.c,v 1.22 2010/06/09 19:20:18 riz Exp $ */
/* $NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $ */
/* cbc.c: This file contains the encryption routines for the ed line editor */
/*-
@ -72,7 +72,7 @@
#if 0
static char *rcsid = "@(#)cbc.c,v 1.2 1994/02/01 00:34:36 alm Exp";
#else
__RCSID("$NetBSD: cbc.c,v 1.22 2010/06/09 19:20:18 riz Exp $");
__RCSID("$NetBSD: cbc.c,v 1.23 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -252,7 +252,7 @@ get_keyword(void)
static void
des_error(const char *s /* the message */)
{
(void)sprintf(errmsg, "%s", s ? s : strerror(errno));
seterrmsg("%s", s ? s : strerror(errno));
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ed.h,v 1.35 2011/08/29 14:51:18 joerg Exp $ */
/* $NetBSD: ed.h,v 1.36 2014/03/23 05:06:42 dholland Exp $ */
/* ed.h: type and constant definitions for the ed editor. */
/*
@ -115,7 +115,7 @@ if (--mutex == 0) { \
errno = 0 ; \
if (((i = strtol(p, &p, 10)) == LONG_MIN || i == LONG_MAX) && \
errno == ERANGE) { \
sprintf(errmsg, "number out of range"); \
seterrmsg("number out of range"); \
i = 0; \
return ERR; \
} \
@ -131,14 +131,14 @@ if ((i) > (n)) { \
if ((b) != NULL) { \
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
sprintf(errmsg, "out of memory"); \
seterrmsg("out of memory"); \
SPL0(); \
return err; \
} \
} else { \
if ((ts = (char *) malloc(ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
sprintf(errmsg, "out of memory"); \
seterrmsg("out of memory"); \
SPL0(); \
return err; \
} \
@ -156,7 +156,7 @@ if ((i) > (n)) { \
SPL1(); \
if ((ts = (char *) realloc((b), ti += max((i), MINBUFSZ))) == NULL) { \
fprintf(stderr, "%s\n", strerror(errno)); \
sprintf(errmsg, "out of memory"); \
seterrmsg("out of memory"); \
SPL0(); \
return err; \
} \
@ -257,6 +257,7 @@ void unmark_line_node(line_t *);
void unset_active_nodes(line_t *, line_t *);
long write_file(const char *, const char *, long, long);
long write_stream(FILE *, long, long);
void seterrmsg(const char *, ...);
/* global buffers */
extern char stdinbuf[];
@ -284,7 +285,7 @@ extern int ere;
extern int des;
extern int newline_added; /* io.c */
extern int patlock;
extern char errmsg[]; /* re.c */
extern char errmsg[]; /* re.c */
extern long u_current_addr; /* undo.c */
extern long u_addr_last; /* undo.c */
#if defined(sun) && !defined(__SVR4)

View File

@ -1,4 +1,4 @@
/* $NetBSD: glbl.c,v 1.6 2005/06/26 19:10:49 christos Exp $ */
/* $NetBSD: glbl.c,v 1.7 2014/03/23 05:06:42 dholland Exp $ */
/* glob.c: This file contains the global command routines for the ed line
editor */
@ -33,7 +33,7 @@
#if 0
static char *rcsid = "@(#)glob.c,v 1.1 1994/02/01 00:34:40 alm Exp";
#else
__RCSID("$NetBSD: glbl.c,v 1.6 2005/06/26 19:10:49 christos Exp $");
__RCSID("$NetBSD: glbl.c,v 1.7 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -54,7 +54,7 @@ build_active_list(int isgcmd)
char delimiter;
if ((delimiter = *ibufp) == ' ' || delimiter == '\n') {
sprintf(errmsg, "invalid pattern delimiter");
seterrmsg("invalid pattern delimiter");
return ERR;
} else if ((pat = get_compiled_pattern()) == NULL)
return ERR;
@ -114,13 +114,13 @@ exec_global(int interact, int gflag)
if (n < 0)
return ERR;
else if (n == 0) {
sprintf(errmsg, "unexpected end-of-file");
seterrmsg("unexpected end-of-file");
return ERR;
} else if (n == 1 && !strcmp(ibuf, "\n"))
continue;
else if (n == 2 && !strcmp(ibuf, "&\n")) {
if (cmd == NULL) {
sprintf(errmsg, "no previous command");
seterrmsg("no previous command");
return ERR;
} else cmd = ocmd;
} else if ((cmd = get_extended_line(&n, 0)) == NULL)
@ -164,7 +164,7 @@ set_active_node(line_t *lp)
if ((ts = (line_t **) realloc(active_list,
(ti += MINBUFSZ) * sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
SPL0();
return ERR;
}
@ -173,7 +173,7 @@ set_active_node(line_t *lp)
if ((ts = (line_t **) malloc((ti += MINBUFSZ) *
sizeof(line_t **))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
SPL0();
return ERR;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $ */
/* $NetBSD: io.c,v 1.10 2014/03/23 05:06:42 dholland Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
/*-
@ -32,7 +32,7 @@
#if 0
static char *rcsid = "@(#)io.c,v 1.1 1994/02/01 00:34:41 alm Exp";
#else
__RCSID("$NetBSD: io.c,v 1.9 2011/05/23 23:13:10 joerg Exp $");
__RCSID("$NetBSD: io.c,v 1.10 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -50,13 +50,13 @@ read_file(char *fn, long n)
fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
sprintf(errmsg, "cannot open input file");
seterrmsg("cannot open input file");
return ERR;
} else if ((size = read_stream(fp, n)) < 0)
return ERR;
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
sprintf(errmsg, "cannot close input file");
seterrmsg("cannot close input file");
return ERR;
}
if (!scripted)
@ -136,7 +136,7 @@ get_stream_line(FILE *fp)
sbuf[i++] = c;
else if (ferror(fp)) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot read input file");
seterrmsg("cannot read input file");
return ERR;
} else if (i) {
sbuf[i++] = '\n';
@ -157,13 +157,13 @@ write_file(const char *fn, const char *mode, long n, long m)
fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
sprintf(errmsg, "cannot open output file");
seterrmsg("cannot open output file");
return ERR;
} else if ((size = write_stream(fp, n, m)) < 0)
return ERR;
else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
sprintf(errmsg, "cannot close output file");
seterrmsg("cannot close output file");
return ERR;
}
if (!scripted)
@ -208,7 +208,7 @@ put_stream_line(FILE *fp, char *s, int len)
while (len--)
if ((des ? put_des_char(*s++, fp) : fputc(*s++, fp)) < 0) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "cannot write file");
seterrmsg("cannot write file");
return ERR;
}
return 0;
@ -239,7 +239,7 @@ get_extended_line(int *sizep, int nonl)
if ((n = get_tty_line()) < 0)
return NULL;
else if (n == 0 || ibuf[n - 1] != '\n') {
sprintf(errmsg, "unexpected end-of-file");
seterrmsg("unexpected end-of-file");
return NULL;
}
REALLOC(cvbuf, cvbufsz, l + n, NULL);
@ -280,7 +280,7 @@ get_tty_line(void)
case EOF:
if (ferror(stdin)) {
fprintf(stderr, "stdin: %s\n", strerror(errno));
sprintf(errmsg, "cannot read stdin");
seterrmsg("cannot read stdin");
clearerr(stdin);
ibufp = NULL;
return ERR;

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.25 2011/08/21 08:40:31 christos Exp $ */
/* $NetBSD: main.c,v 1.26 2014/03/23 05:06:42 dholland Exp $ */
/* main.c: This file contains the main control and user-interface routines
for the ed line editor. */
@ -39,7 +39,7 @@ __COPYRIGHT(
#if 0
static char *rcsid = "@(#)main.c,v 1.1 1994/02/01 00:34:42 alm Exp";
#else
__RCSID("$NetBSD: main.c,v 1.25 2011/08/21 08:40:31 christos Exp $");
__RCSID("$NetBSD: main.c,v 1.26 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -168,7 +168,7 @@ top:
#endif
{
fputs("\n?\n", stderr);
sprintf(errmsg, "interrupt");
seterrmsg("interrupt");
} else {
init_buffers();
sigactive = 1; /* enable signal handlers */
@ -181,7 +181,7 @@ top:
} else if (argc) {
fputs("?\n", stderr);
if (**argv == '\0')
sprintf(errmsg, "invalid filename");
seterrmsg("invalid filename");
if (!isatty(0))
quit(2);
}
@ -199,7 +199,7 @@ top:
} else if (n == 0) {
if (modified && !scripted) {
fputs("?\n", stderr);
sprintf(errmsg, "warning: file modified");
seterrmsg("warning: file modified");
if (!isatty(0)) {
if (garrulous) {
fprintf(stderr,
@ -216,7 +216,7 @@ top:
quit(0);
} else if (ibuf[n - 1] != '\n') {
/* discard line */
sprintf(errmsg, "unexpected end-of-file");
seterrmsg("unexpected end-of-file");
clearerr(stdin);
status = ERR;
continue;
@ -234,7 +234,7 @@ top:
case EMOD:
modified = 0;
fputs("?\n", stderr); /* give warning */
sprintf(errmsg, "warning: file modified");
seterrmsg("warning: file modified");
if (!isatty(0)) {
if (garrulous) {
fprintf(stderr,
@ -300,7 +300,7 @@ extract_addr_range(void)
ibufp++
#define MUST_BE_FIRST() \
if (!first) { sprintf(errmsg, "invalid address"); return ERR; }
if (!first) { seterrmsg("invalid address"); return ERR; }
/* next_addr: return the next line address in the command buffer */
long
@ -370,7 +370,7 @@ next_addr(void)
if (ibufp == hd)
return EOF;
else if (addr < 0 || addr_last < addr) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
} else
return addr;
@ -389,10 +389,10 @@ next_addr(void)
if (extract_addr_range() < 0) \
return ERR; \
else if (addr_cnt == 0) { \
sprintf(errmsg, "destination expected"); \
seterrmsg("destination expected"); \
return ERR; \
} else if (second_addr < 0 || addr_last < second_addr) { \
sprintf(errmsg, "invalid address"); \
seterrmsg("invalid address"); \
return ERR; \
} \
addr = second_addr; \
@ -408,7 +408,7 @@ next_addr(void)
if (extract_addr_range() < 0) \
return ERR; \
if (second_addr < 0 || addr_last < second_addr) { \
sprintf(errmsg, "invalid address"); \
seterrmsg("invalid address"); \
return ERR; \
} \
addr = second_addr; \
@ -436,7 +436,7 @@ next_addr(void)
} \
} while (!done); \
if (*ibufp++ != '\n') { \
sprintf(errmsg, "invalid command suffix"); \
seterrmsg("invalid command suffix"); \
return ERR; \
} \
}
@ -502,10 +502,10 @@ exec_command(void)
/* fall through */
case 'E':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
} else if (!isspace((unsigned char)*ibufp)) {
sprintf(errmsg, "unexpected command suffix");
seterrmsg("unexpected command suffix");
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
@ -521,7 +521,7 @@ exec_command(void)
sizeof(old_filename) - 2);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
sprintf(errmsg, "no current filename");
seterrmsg("no current filename");
return ERR;
}
#endif
@ -533,15 +533,15 @@ exec_command(void)
break;
case 'f':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
} else if (!isspace((unsigned char)*ibufp)) {
sprintf(errmsg, "unexpected command suffix");
seterrmsg("unexpected command suffix");
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
else if (*fnp == '!') {
sprintf(errmsg, "invalid redirection");
seterrmsg("invalid redirection");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -553,7 +553,7 @@ exec_command(void)
case 'G':
case 'V':
if (isglobal) {
sprintf(errmsg, "cannot nest global commands");
seterrmsg("cannot nest global commands");
return ERR;
} else if (check_addr_range(1, addr_last) < 0)
return ERR;
@ -567,7 +567,7 @@ exec_command(void)
break;
case 'h':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -575,7 +575,7 @@ exec_command(void)
break;
case 'H':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -584,7 +584,7 @@ exec_command(void)
break;
case 'i':
if (second_addr == 0) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -604,7 +604,7 @@ exec_command(void)
case 'k':
c = *ibufp++;
if (second_addr == 0) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -624,7 +624,7 @@ exec_command(void)
return ERR;
GET_THIRD_ADDR(addr);
if (first_addr <= addr && addr < second_addr) {
sprintf(errmsg, "invalid destination");
seterrmsg("invalid destination");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -650,7 +650,7 @@ exec_command(void)
break;
case 'P':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -659,7 +659,7 @@ exec_command(void)
case 'q':
case 'Q':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -667,7 +667,7 @@ exec_command(void)
break;
case 'r':
if (!isspace((unsigned char)*ibufp)) {
sprintf(errmsg, "unexpected command suffix");
seterrmsg("unexpected command suffix");
return ERR;
} else if (addr_cnt == 0)
second_addr = addr_last;
@ -679,7 +679,7 @@ exec_command(void)
strlcpy(old_filename, fnp, sizeof(old_filename) - 2);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
sprintf(errmsg, "no current filename");
seterrmsg("no current filename");
return ERR;
}
#endif
@ -714,18 +714,18 @@ exec_command(void)
break;
default:
if (sflags) {
sprintf(errmsg, "invalid command suffix");
seterrmsg("invalid command suffix");
return ERR;
}
}
} while (sflags && *ibufp != '\n');
if (sflags && !pat) {
sprintf(errmsg, "no previous substitution");
seterrmsg("no previous substitution");
return ERR;
} else if (sflags & SGG)
sgnum = 0; /* override numeric arg */
if (*ibufp != '\n' && *(ibufp + 1) == '\n') {
sprintf(errmsg, "invalid pattern delimiter");
seterrmsg("invalid pattern delimiter");
return ERR;
}
tpat = pat;
@ -786,7 +786,7 @@ exec_command(void)
break;
case 'u':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
@ -800,7 +800,7 @@ exec_command(void)
ibufp++;
}
if (!isspace((unsigned char)*ibufp)) {
sprintf(errmsg, "unexpected command suffix");
seterrmsg("unexpected command suffix");
return ERR;
} else if ((fnp = get_filename()) == NULL)
return ERR;
@ -813,7 +813,7 @@ exec_command(void)
strlcpy(old_filename, fnp, sizeof(old_filename) - 2);
#ifdef BACKWARDS
if (*fnp == '\0' && *old_filename == '\0') {
sprintf(errmsg, "no current filename");
seterrmsg("no current filename");
return ERR;
}
#endif
@ -827,14 +827,14 @@ exec_command(void)
break;
case 'x':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
}
GET_COMMAND_SUFFIX();
#ifdef DES
des = get_keyword();
#else
sprintf(errmsg, "crypt unavailable");
seterrmsg("crypt unavailable");
return ERR;
#endif
break;
@ -859,7 +859,7 @@ exec_command(void)
break;
case '!':
if (addr_cnt > 0) {
sprintf(errmsg, "unexpected address");
seterrmsg("unexpected address");
return ERR;
} else if ((sflags = get_shell_command()) < 0)
return ERR;
@ -878,7 +878,7 @@ exec_command(void)
return ERR;
break;
default:
sprintf(errmsg, "unknown command");
seterrmsg("unknown command");
return ERR;
}
return gflag;
@ -895,7 +895,7 @@ check_addr_range(long n, long m)
}
if (first_addr > second_addr || 1 > first_addr ||
second_addr > addr_last) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
}
return 0;
@ -925,7 +925,7 @@ get_matching_node_addr(pattern_t *pat, int dir)
return n;
}
} while (n != current_addr);
sprintf(errmsg, "no match");
seterrmsg("no match");
return ERR;
}
@ -942,7 +942,7 @@ get_filename(void)
if (*ibufp != '\n') {
SKIP_BLANKS();
if (*ibufp == '\n') {
sprintf(errmsg, "invalid filename");
seterrmsg("invalid filename");
return NULL;
} else if ((ibufp = get_extended_line(&n, 1)) == NULL)
return NULL;
@ -953,13 +953,13 @@ get_filename(void)
if (n) printf("%s\n", shcmd + 1);
return shcmd;
} else if (n - 1 > MAXPATHLEN) {
sprintf(errmsg, "filename too long");
seterrmsg("filename too long");
return NULL;
}
}
#ifndef BACKWARDS
else if (*old_filename == '\0') {
sprintf(errmsg, "no current filename");
seterrmsg("no current filename");
return NULL;
}
#endif
@ -984,7 +984,7 @@ get_shell_command(void)
int j = 0;
if (red) {
sprintf(errmsg, "shell access restricted");
seterrmsg("shell access restricted");
return ERR;
} else if ((s = ibufp = get_extended_line(&j, 1)) == NULL)
return ERR;
@ -1009,7 +1009,7 @@ get_shell_command(void)
else if (shcmd == NULL)
#endif
{
sprintf(errmsg, "no previous command");
seterrmsg("no previous command");
return ERR;
} else {
REALLOC(buf, n, i + shcmdi, ERR);
@ -1020,7 +1020,7 @@ get_shell_command(void)
break;
case '%':
if (*old_filename == '\0') {
sprintf(errmsg, "no current filename");
seterrmsg("no current filename");
return ERR;
}
j = strlen(s = strip_escapes(old_filename));
@ -1238,7 +1238,7 @@ display_lines(long from, long to, int gflag)
char *s;
if (!from) {
sprintf(errmsg, "invalid address");
seterrmsg("invalid address");
return ERR;
}
ep = get_addressed_line_node(INC_MOD(to, addr_last));
@ -1263,7 +1263,7 @@ int
mark_line_node(line_t *lp, int n)
{
if (!islower(n)) {
sprintf(errmsg, "invalid mark character");
seterrmsg("invalid mark character");
return ERR;
} else if (mark[n - 'a'] == NULL)
markno++;
@ -1277,7 +1277,7 @@ long
get_marked_node_addr(int n)
{
if (!islower(n)) {
sprintf(errmsg, "invalid mark character");
seterrmsg("invalid mark character");
return ERR;
}
return get_line_node_addr(mark[n - 'a']);
@ -1306,7 +1306,7 @@ dup_line_node(line_t *lp)
if ((np = (line_t *) malloc(sizeof(line_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
return NULL;
}
np->seek = lp->seek;
@ -1418,7 +1418,7 @@ int
is_legal_filename(char *s)
{
if (red && (*s == '!' || !strcmp(s, "..") || strchr(s, '/'))) {
sprintf(errmsg, "shell access restricted");
seterrmsg("shell access restricted");
return 0;
}
return 1;

View File

@ -1,4 +1,4 @@
/* $NetBSD: re.c,v 1.20 2013/06/28 15:04:35 joerg Exp $ */
/* $NetBSD: re.c,v 1.21 2014/03/23 05:06:42 dholland Exp $ */
/* re.c: This file contains the regular expression interface routines for
the ed line editor. */
@ -33,15 +33,26 @@
#if 0
static char *rcsid = "@(#)re.c,v 1.6 1994/02/01 00:34:43 alm Exp";
#else
__RCSID("$NetBSD: re.c,v 1.20 2013/06/28 15:04:35 joerg Exp $");
__RCSID("$NetBSD: re.c,v 1.21 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
#include <stdarg.h>
#include "ed.h"
char errmsg[MAXPATHLEN + 40] = "";
void
seterrmsg(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
va_end(ap);
}
/* get_compiled_pattern: return pointer to compiled pattern from command
buffer */
pattern_t *
@ -54,10 +65,10 @@ get_compiled_pattern(void)
int n;
if ((delimiter = *ibufp) == ' ') {
sprintf(errmsg, "invalid pattern delimiter");
seterrmsg("invalid pattern delimiter");
return NULL;
} else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) {
if (!expr) sprintf(errmsg, "no previous pattern");
if (!expr) seterrmsg("no previous pattern");
return expr;
} else if ((exps = extract_pattern(delimiter)) == NULL)
return NULL;
@ -66,7 +77,7 @@ get_compiled_pattern(void)
regfree(expr);
else if ((expr = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
return NULL;
}
patlock = 0;
@ -96,13 +107,13 @@ extract_pattern(int delimiter)
break;
case '[':
if ((nd = parse_char_class(nd + 1)) == NULL) {
sprintf(errmsg, "unbalanced brackets ([])");
seterrmsg("unbalanced brackets ([])");
return NULL;
}
break;
case '\\':
if (*++nd == '\n') {
sprintf(errmsg, "trailing backslash (\\)");
seterrmsg("trailing backslash (\\)");
return NULL;
}
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: sub.c,v 1.6 2005/02/17 16:29:26 xtraeme Exp $ */
/* $NetBSD: sub.c,v 1.7 2014/03/23 05:06:42 dholland Exp $ */
/* sub.c: This file contains the substitution routines for the ed
line editor */
@ -33,7 +33,7 @@
#if 0
static char *rcsid = "@(#)sub.c,v 1.1 1994/02/01 00:34:44 alm Exp";
#else
__RCSID("$NetBSD: sub.c,v 1.6 2005/02/17 16:29:26 xtraeme Exp $");
__RCSID("$NetBSD: sub.c,v 1.7 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -86,7 +86,9 @@ extract_subst_template(void)
if (*ibufp == '%' && *(ibufp + 1) == delimiter) {
ibufp++;
if (!rhbuf) sprintf(errmsg, "no previous substitution");
if (!rhbuf) {
seterrmsg("no previous substitution");
}
return rhbuf;
}
while (*ibufp != delimiter) {
@ -160,7 +162,7 @@ search_and_replace(pattern_t *pat, int gflag, int kth)
}
current_addr = xa;
if (nsubs == 0 && !(gflag & GLB)) {
sprintf(errmsg, "no match");
seterrmsg("no match");
return ERR;
} else if ((gflag & (GPR | GLS | GNP)) &&
display_lines(current_addr, current_addr, gflag) < 0)
@ -214,7 +216,7 @@ substitute_matching_text(pattern_t *pat, line_t *lp, int gflag, int kth)
i = eot - txt;
REALLOC(rbuf, rbufsz, off + i + 2, ERR);
if (i > 0 && !rm[0].rm_eo && (gflag & GSG)) {
sprintf(errmsg, "infinite substitution loop");
seterrmsg("infinite substitution loop");
return ERR;
}
if (isbinary)

View File

@ -1,4 +1,4 @@
/* $NetBSD: undo.c,v 1.5 2007/03/17 13:51:46 msaitoh Exp $ */
/* $NetBSD: undo.c,v 1.6 2014/03/23 05:06:42 dholland Exp $ */
/* undo.c: This file contains the undo routines for the ed line editor */
/*-
@ -32,7 +32,7 @@
#if 0
static char *rcsid = "@(#)undo.c,v 1.1 1994/02/01 00:34:44 alm Exp";
#else
__RCSID("$NetBSD: undo.c,v 1.5 2007/03/17 13:51:46 msaitoh Exp $");
__RCSID("$NetBSD: undo.c,v 1.6 2014/03/23 05:06:42 dholland Exp $");
#endif
#endif /* not lint */
@ -54,7 +54,7 @@ push_undo_stack(int type, long from, long to)
if (ustack == NULL &&
(ustack = (undo_t *) malloc((usize = USIZE) * sizeof(undo_t))) == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
return NULL;
}
#endif
@ -69,7 +69,7 @@ push_undo_stack(int type, long from, long to)
}
/* out of memory - release undo stack */
fprintf(stderr, "%s\n", strerror(errno));
sprintf(errmsg, "out of memory");
seterrmsg("out of memory");
clear_undo_stack();
free(ustack);
ustack = NULL;
@ -97,7 +97,7 @@ pop_undo_stack(void)
long o_addr_last = addr_last;
if (u_current_addr == -1 || u_addr_last == -1) {
sprintf(errmsg, "nothing to undo");
seterrmsg("nothing to undo");
return ERR;
} else if (u_p)
modified = 1;