Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #103413
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Masking the password entered by the user |
| Date | 2017-02-07 19:39 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87zihxaize.fsf@bsb.me.uk> (permalink) |
| References | <6fb9a4db-5cba-479c-8ee6-82b7146a2e38@googlegroups.com> |
Alla _ <modelling.data@gmail.com> writes:
> char *user_pass()
> {
> char *password = NULL;
> if(!(password = buff_alloc()))
I'd initialise with the correct value. Don't make setting things to
zero or NULL a knee-jerk reaction!
And I prefer to be positive:
char *password = buff_alloc();
if (password) {
... read in the characters ...
}
return password;
but there are two sides to this.
> return NULL;
> int c;
> int i = 0;
>
> while( (c = getchar()) != EOF && (c != '\n' && c != '\r'))
> password[i++] = c;
Buffer overflow.
> if (c == '\n')
> password[i] = '\0';
You always want to return a string so there should be nothing special
about \n.
> return password;
> }
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Masking the password entered by the user Alla _ <modelling.data@gmail.com> - 2017-02-07 09:19 -0800
Re: Masking the password entered by the user Keith Thompson <kst-u@mib.org> - 2017-02-07 09:34 -0800
Re: Masking the password entered by the user "James R. Kuyper" <jameskuyper@verizon.net> - 2017-02-07 12:54 -0500
Re: Masking the password entered by the user Alla _ <modelling.data@gmail.com> - 2017-02-07 10:21 -0800
Re: Masking the password entered by the user Keith Thompson <kst-u@mib.org> - 2017-02-07 12:16 -0800
Re: Masking the password entered by the user luser droog <luser.droog@gmail.com> - 2017-02-07 11:10 -0800
Re: Masking the password entered by the user Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-07 19:39 +0000
Re: Masking the password entered by the user Alla _ <modelling.data@gmail.com> - 2017-02-07 12:21 -0800
csiph-web