public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Re: Buffer size checking for scanf* functions
@ 2022-07-05 21:50 Yair Lenga
  2022-07-06 12:10 ` Adhemerval Zanella
  0 siblings, 1 reply; 6+ messages in thread
From: Yair Lenga @ 2022-07-05 21:50 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-help


> 
> Adhemerval,

Thanks for taking time to review my posting.

I agree 100% with the critic on annex K. I believe there is (almost) universal agreement that it was half baked solution, rushed into the standard without proper review - which is why it got very little traction.

However, the fact the the annex K has many flaws does not mean that there are no good ideas in it. In particular, the ability to create “safer” vararg lists for atomic types, and use them in scanf* and similar, is significant improvement (IHMO). I believe it improve safety, while keeping code clean, readable, and can be used for many use cases (e.g., my scanf from a result set, parsing csv-like data, …).

Also worth mentioning that one mentioned alternative (OBS - object size checking) can fit into the proposed scanf change, given it ability to identify object sizes for static/dynamic char *.

Hoping to get feedback on my proposal for this limited use case.

Also, regarding the proposal for using stringifying macros, etc. Those are interesting ideas, but will break code clarity/readability . They Will not fit nicely into large scale projects, given their limitation (e.g. with dynamic size strings, etc.)

Thanks again for your time/ideas/feedback,

Yair

Sent from my iPad

> On Jul 5, 2022, at 3:39 PM, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> The glibc does not support hooks for scanf and I don’t think we will even
> will, the printf hooks itself has some drawbacks (MT-safeness, etc.).  Also
> scan_s and similar ‘enhanced’ functions from TR-24731 have not been widely 
> implemented mainly because they do not actually improve much. Carlos and
> Martim, both GNU developers, wrote a paper discussing the problems with
> these interfaces [1].

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Buffer size checking for scanf* functions
@ 2022-07-05  7:31 Yair Lenga
  2022-07-05 12:39 ` Adhemerval Zanella
  0 siblings, 1 reply; 6+ messages in thread
From: Yair Lenga @ 2022-07-05  7:31 UTC (permalink / raw)
  To: libc-help

Hi,

Looking for feedback on the following age-old scanf problem: I'm trying to
perform a "safe' scanf, which will avoid buffer overflow.

#define XSIZE 30
char x[XSIZE] ;
sscanf(input, "%29s", x) ;

With the common pitfall that anytime the size of X is changed, the format
string MUST to be modified. One common approach, with glibc, is to use the
'm' modifier, switch x to char **x. However, this require code changes, and
is not practical with my existing code base.

My question: is there any extension to allow scanf to take an extra
argument (similar to the scanf_s proposal) - specifying the sizeof any
string arguments ?
sscanf(input, "%S", x, sizeof(x)) ;     // The 'S' require adding sizeof
parameter ?

If there is no such extension - how hard it will be to implement. I know
possible to define custom conversions for printf, I could not find anything
for scanf. IF this will be built into 'glibc', there IF it will be embedded
into the gcc format checks (2 big IFs), it can reduce the problems I (and I
believe many other developers) face when using those functions.

Yair

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-07-11 12:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 21:50 Buffer size checking for scanf* functions Yair Lenga
2022-07-06 12:10 ` Adhemerval Zanella
2022-07-06 15:04   ` Yair Lenga
2022-07-11 12:38     ` Adhemerval Zanella
  -- strict thread matches above, loose matches on Subject: below --
2022-07-05  7:31 Yair Lenga
2022-07-05 12:39 ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).