Bug 53940 - scanf(3) doesn't seem to handle %n properly
scanf(3) doesn't seem to handle %n properly
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
7.1
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-09-23 07:10 EDT by Stas Sergeev
Modified: 2016-11-24 09:47 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-09-23 07:12:44 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
simple test program for scanf() (203 bytes, patch)
2001-09-23 07:12 EDT, Stas Sergeev
no flags Details | Diff

  None (edit)
Description Stas Sergeev 2001-09-23 07:10:25 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.19 i686)

Description of problem:
If scanf() reads no symbols, it ignores %n

Version-Release number of selected component (if applicable):
all versions.

How reproducible:
Always

Steps to Reproduce:
1. Compile the test program (attached)
2. run it

	

Actual Results:  10 3

Expected Results:  0 3

Additional info:

Not shure that it is a bug, but I have one program that crashes due
to this strange behavior.
Comment 1 Stas Sergeev 2001-09-23 07:12:40 EDT
Created attachment 32418 [details]
simple test program for scanf()
Comment 2 Jakub Jelinek 2001-09-24 05:15:42 EDT
It is a bug, but not in glibc, but in the program you have.
In first sscanf, you get matching failure already before the %n directive,
so it is not assigned. See e.g. ISO C99, or
http://www.opengroup.org/onlinepubs/007908799/xsh/fscanf.html
You really have to check *scanf return value first before assuming which
arguments were assigned to.

Note You need to log in before you can comment on or make changes to this bug.