X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f X-Recipient: djgpp-workers AT delorie DOT com X-Authenticated: #27081556 X-Provags-ID: V01U2FsdGVkX1+padEhsn2pKffCzaFlbXMPrXmTTqFIn/J877cmud 3IqEZCM+Te+CSf From: Juan Manuel Guerrero To: djgpp-workers AT delorie DOT com Subject: Re: [patch] kill gets() usage in stubedit.c, use fgets() Date: Sat, 2 Jul 2011 20:32:10 +0200 User-Agent: KMail/1.9.10 References: <201107021926 DOT 48563 DOT juan DOT guerrero AT gmx DOT de> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201107022032.10137.juan.guerrero@gmx.de> X-Y-GMX-Trusted: 0 Reply-To: djgpp-workers AT delorie DOT com Am Samstag, 2. Juli 2011 schrieb Ozkan Sezer: [snip] > Quick scanning reveals: > > src/utils/djtar/djtar.c: line #208: Missed this because I never use > it, not needed in cross-tools > > src/libc/dos/dir/fnsplit.c::main() line #119 (but that's only TEST code, > not compiled into lib.) Yes, I found the same. The proposed changes seem ok to me. If no one oposses I will commit the patch below. Regards, Juan M. Guerrero * src/stub/stubedit.c: Use fgets instead of gets. From Ozkan Sezer * src/utils/djtar/djtar.c: Use fgets instead of gets. From Ozkan Sezer diff -aprNU3 djgpp.orig/src/stub/stubedit.c djgpp/src/stub/stubedit.c --- djgpp.orig/src/stub/stubedit.c 2003-01-05 17:59:26 +0000 +++ djgpp/src/stub/stubedit.c 2011-07-02 20:20:40 +0000 @@ -87,9 +87,20 @@ void store_info(char *filename) char *pose_question(char *question, char *default_answer) { static char response[200]; + char *ptr; printf("%s ? [%s] ", question, default_answer); fflush(stdout); - gets(response); + ptr = fgets(response, sizeof(response), stdin); + if (!ptr) + return 0; + for (; *ptr; ++ptr) + { + if (*ptr == '\n') + { + *ptr = '\0'; + break; + } + } if (response[0] == '\0') return 0; return response; diff -aprNU3 djgpp.orig/src/utils/djtar/djtar.c djgpp/src/utils/djtar/djtar.c --- djgpp.orig/src/utils/djtar/djtar.c 2011-02-26 19:52:06 +0000 +++ djgpp/src/utils/djtar/djtar.c 2011-07-02 20:27:00 +0000 @@ -205,12 +205,21 @@ change(char *fname, const char *problem, fprintf(log_out, " %s %s\n new name : ", problem, fname); fflush(log_out); new[0] = '\0'; - if (!gets(new)) + pos = fgets(new, sizeof(new), stdin); + if (!pos) Fatal("EOF while reading stdin"); + for (; *pos; ++pos) + { + if (*pos == '\n') + { + *pos = '\0'; + break; + } + } - if ((strcmp(new, "") == 0) && (isadir == 2)) + if ((new[0] == '\0') && (isadir == 2)) return 0; - if (isadir) isadir=1; + if (isadir) isadir = 1; ch = (CHANGE *)xmalloc(sizeof(CHANGE)); ch->next = change_root; change_root = ch;