NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/58453: endptr can be unitialized if an invalid base is passed to strto*(3)



The following reply was made to PR lib/58453; it has been noted by GNATS.

From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: gnats-bugs%netbsd.org@localhost, christos%astron.com@localhost, netbsd-bugs%netbsd.org@localhost
Cc: 
Subject: Re: lib/58453: endptr can be unitialized if an invalid base is passed to strto*(3)
Date: Tue, 23 Jul 2024 04:52:30 +0700

 What exactly is this bug report about?
 
 The referenced message from Alejandro Colomar is about about
 just strtoi() (which used strtoimax() incorrectly) and which
 you fixed.
 
 That the other strto*() functions don't leave any defined value
 in *endptr when an invalid base is provided (which is really just
 a bug in the application) isn't unexpected, as Alejandro's 2nd
 message indicates, and POSIX makes expicit:
 
 APPLICATION USAGE
             Since the value of *endptr is unspecified if the value of base
 	    is not supported, applications should either ensure that base
             has a supported value (0 or between 2 and 36) before the call,
 	    or check for an [EINVAL] error before examining *endptr.
 
 The test program provided in this PR is incorrect, as it fails to make that
 check (especially as it is explicitly providing an invalid base).
 
 kre
 
 ps: Note that this doesn't mean that we couldn't put something specific
 in *endptr in the case of an invalid base, but anything which ends up
 relying upon that would be broken.  Perhaps we could set it to NULL or
 (void *)-1 so any attempt to dereference it would fault, though technically
 simply referencing it is UB.
 
 


Home | Main Index | Thread Index | Old Index