From 490fbda2dfc7b0ba9a3e75fb5823f730e588c5db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Groenvall?= Date: Sun, 22 Mar 1998 11:34:54 +0000 Subject: [PATCH] Fix buffer overrun and non terminated string problem. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4651 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/xnlock/xnlock.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/appl/xnlock/xnlock.c b/appl/xnlock/xnlock.c index 608275147..dc2d36179 100644 --- a/appl/xnlock/xnlock.c +++ b/appl/xnlock/xnlock.c @@ -169,25 +169,28 @@ static char* get_words(void) { FILE *pp = NULL; - static char buf[BUFSIZ]; + static char buf[512]; + long n; - if(appres.text_prog){ + if (appres.text_prog) { pp = popen(appres.text_prog, "r"); - if(!pp){ - warn ("popen %s", appres.text_prog); + if (!pp) { + warn("popen %s", appres.text_prog); return appres.text; } - fread(buf, BUFSIZ, 1, pp); + n = fread(buf, 1, sizeof(buf) - 1, pp); + buf[n] = 0; pclose(pp); return buf; } - if(appres.file){ + if (appres.file) { pp = fopen(appres.file, "r"); - if(!pp){ - warn ("fopen %s", appres.file); + if (!pp) { + warn("fopen %s", appres.file); return appres.text; } - fread(buf, BUFSIZ, 1, pp); + n = fread(buf, 1, sizeof(buf) - 1, pp); + buf[n] = 0; fclose(pp); return buf; }