anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

commit a02cdf22bc54e981c522aa3896299087ed518703
parent ab96bdfada8ecb22c60b752fa9699fc454899b2d
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 29 Jul 2026 13:08:26 +0200

CH_AHV: reject empty input instead of reading before the buffer

Diffstat:
Msrc/reducer/validation_CH_AHV.c | 8+++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/reducer/validation_CH_AHV.c b/src/reducer/validation_CH_AHV.c @@ -38,10 +38,16 @@ CH_AHV_check (const char *ahv_number) { unsigned int checknum; unsigned int next_ten; - const char *pos = &ahv_number[strlen (ahv_number) - 1]; + size_t len = strlen (ahv_number); + const char *pos; bool phase = true; unsigned int calculation = 0; + /* Guard against empty input: strlen()-1 would wrap and read one byte + before the buffer. A valid AHV number is 13 digits (optionally dotted). */ + if (0 == len) + return false; + pos = &ahv_number[len - 1]; checknum = *pos - 48; while (pos > ahv_number) {