From 09f8dcc90e03b16b2fe330818892dc9237368d77 Mon Sep 17 00:00:00 2001 From: Jesse Smith Date: Sun, 27 Jan 2019 16:04:13 -0400 Subject: [PATCH] Updated wall.c to make it easier to adjust buffer sizes without causing overflow or off-by-one errors. --- src/wall.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wall.c b/src/wall.c index 4352b0f..d3a2c70 100644 --- a/src/wall.c +++ b/src/wall.c @@ -34,12 +34,13 @@ #define MAXLEN 4096 +#define LINE_SIZE 80 #define MAXLINES 20 int main(int argc, char **argv) { char buf[MAXLEN]; - char line[83]; + char line[LINE_SIZE + 3]; /* leave room for \r\n\0 */ int i, f, ch; int len = 0; int remote = 0; @@ -81,7 +82,7 @@ int main(int argc, char **argv) if ((argc - optind) > 0) { for(f = optind; f < argc; f++) { len += strlen(argv[f]) + 1; - if (len >= MAXLEN-2) break; + if (len >= MAXLEN-4) break; strcat(buf, argv[f]); if (f < argc-1) strcat(buf, " "); }