# fgets()/fgetss() BC break in HEAD

- Thread: https://externals.io/message/26638
- Original archive: https://news-web.php.net/php.internals/26638
- Started by Sara Golemon on 2006-11-16T04:48:36+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26638 — Sara Golemon — 2006-11-16T04:48:36+00:00

URL: https://externals.io/message/26638#26638

Zeev-

> My IQ is higher than 12, and I don't see how defensive coding could have 
> defended against this BC break.  This code is missing error checking, 
> but that could be quite reasonable (e.g. if you check ahead of time that 
> the file is big enough to match the format you're expecting - so it's 
> not perfect, but it's quite reasonable).  But even if it did have error 
> checking, it would look something like this:
> 
You're ignoring the fact that `fgets()` is the wrong tool for this job. 
This is something for `fread()`.  "I want to read precisely X bytes.  I 
know! I'll use a function which halts at a newline character."  This 
isn't accidental reasoning of someone who "doesn't have the time to read 
every page of the manual",  This is taking antibiotics for a flu.

> So, after the BC break, it'd barf.  There's really no way to protect 
> against this BC break, and it's pretty clear this behavior is being 
> relied upon.
> 
By one project. Which is very clearly using `fgets()` to do what `fgetc()` 
should be doing.

> > […]
> 
> That's fine by me, but I think it's a different issue.  The BC break 
> should be reverted irregardless...
> 
Just to be clear, noone's arguing against reversion.  I accepted before 
this thread ever started that while the current logic is broken, there's 
no driving force to fix it.


Stas-

   Please don't misquote me.  While I admit my crack about the stupidity 
of anyone relying on this behavior was uncalled for, your fictionalized 
summary was just that.  Fiction.  Get your facts straight.

-Sara

---

## #26639 — Zeev Suraski — 2006-11-16T11:37:44+00:00

URL: https://externals.io/message/26638#26639 · In reply to: #26638

At 06:48 16/11/2006, Sara Golemon wrote:
>Zeev-
>
> > […]
>You're ignoring the fact that `fgets()` is the wrong tool for this 
>job. This is something for `fread()`.  "I want to read precisely X 
>bytes.  I know! I'll use a function which halts at a newline 
>character."  This isn't accidental reasoning of someone who "doesn't 
>have the time to read every page of the manual",  This is taking 
>antibiotics for a flu.

I'm not ignoring that fact at all (well I did in this particular 
email, but not beforehand).  I know it's designed to read full 
lines.  But do you really think it's not being used for reading a 
specific number of bytes as well?  Especially considering the fact 
that if you go to the documentation, `fputs()` is documented as an 
alias of `fwrite()` (IIRC).
Whether this is or isn't the right tool for the job is beside the 
point IMHO.  Fact is it *is* being used that way, and it will break 
apps if changed.

> > […]
>By one project. Which is very clearly using `fgets()` to do what 
>fgetc() should be doing.

That's just one project on Google Code, and Ilia's search was only 
for reading of two bytes IIRC.
Anyway, if there's one, there's plenty.  That's an axiom :)

> > […]
>Just to be clear, noone's arguing against reversion.  I accepted 
>before this thread ever started that while the current logic is 
>broken, there's no driving force to fix it.

Yep I know.   We're just having fun discussing it aren't we :)

Zeev
