Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #103413
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
| Newsgroups | comp.lang.c |
| Subject | Re: Masking the password entered by the user |
| Date | Tue, 07 Feb 2017 19:39:17 +0000 |
| Organization | A noiseless patient Spider |
| Lines | 40 |
| Message-ID | <87zihxaize.fsf@bsb.me.uk> (permalink) |
| References | <6fb9a4db-5cba-479c-8ee6-82b7146a2e38@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="6b16403c060c76fc53ae0c0bdb247f77"; logging-data="7980"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DQdIjz91W0B9Ky7993pL2cyr7ACmP0ug=" |
| Cancel-Lock | sha1:23GJqGnBIJyxb50fRoqHtzXWuYc= sha1:wXYCYE8DMzaGpgY3k9lJSnFAaxE= |
| X-BSB-Auth | 1.17721f09b3d83232384d.20170207193917GMT.87zihxaize.fsf@bsb.me.uk |
| Xref | csiph.com comp.lang.c:103413 |
Show key headers only | View raw
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