Austin Group Defect Tracker

Aardvark Mark III


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000174 [1003.1(2008)/Issue 7] System Interfaces Objection Enhancement Request 2009-10-29 18:21 2009-11-12 16:39
Reporter drepper View Status public  
Assigned To ajosey
Priority normal Resolution Accepted As Marked  
Status Resolved  
Name Ulrich Drepper
Organization Red Hat, Inc.
User Reference ud-puts-overflow
Section puts()
Page Number 1723
Line Number 55058
Interp Status ---
Final Accepted Text Note: 0000298
Summary 0000174: puts for strings longer than INT_MAX
Description Strings do not have a length limit and on systems with, say, 64-bit address space and int being 32-bit, the result of calls to puts with strings as parameter of length > INT_MAX is unspecified. We cannot return the number of written bytes because all successful calls must return a non-negative value.

The same applies to fputs.
Desired Action There are two ways out:

- forbid such calls outright. In this case:

  1. copy the ERRORS section for fputc to puts() and fputs().
  2. add new error case

      [EOVERFLOW] The string /s/ is too long.

- truncate the write at INT_MAX characters and have the app handle this.
Tags c99, tc1-2008
Attached Files

- Relationships

-  Notes
(0000271)
nick (manager)
2009-10-29 18:32

Discussed with some members of the C meeting after we adjourned ... general feeling is that this is undefined, and the EOVERFLOW error is an appropriate POSIX CX extension.
(0000272)
cmsmith (reporter)
2009-10-29 21:09

The return value for fputs() and puts() is "a non-negative number" upon success. The description does not indicate that the value needs to be related to the number of characters written.
(0000273)
drepper (reporter)
2009-10-29 22:58

Agreed, the value need not be the number of written bytes. But it'll break existing code to change that. Of course we can just return INT_MAX for all strings > INT_MAX. I guess this makes this a non-issue here.
(0000274)
geoffclare (manager)
2009-10-30 09:51

I agree no change to the normative text is needed, but I think we
should add some rationale or app usage about this issue. Perhaps
something like:

    "Traditionally puts() returned the number of bytes written.
    However, this convention cannot be adhered to for strings
    longer than INT_MAX bytes as the value would not be
    representable in the return type of the function. For
    backwards compatibility, implementations can return the
    number of bytes for strings of up to INT_MAX bytes, and
    return INT_MAX for all longer strings."
(0000298)
msbrown (manager)
2009-11-12 16:38

Add the following to the Application Usage section of puts(), p1723 after line 55077:

 "In some implementations puts() returned the number of bytes written.
    However, this convention cannot be adhered to for strings
    longer than INT_MAX bytes as the value would not be
    representable in the return type of the function. For
    backwards compatibility, implementations can return the
    number of bytes for strings of up to INT_MAX bytes, and
    return INT_MAX for all longer strings."

Also the same on page 908 after line 30373, with puts() changed to fputs().

- Issue History
Date Modified Username Field Change
2009-10-29 18:21 drepper New Issue
2009-10-29 18:21 drepper Status New => Under Review
2009-10-29 18:21 drepper Assigned To => ajosey
2009-10-29 18:21 drepper Name => Ulrich Drepper
2009-10-29 18:21 drepper Organization => Red Hat, Inc.
2009-10-29 18:21 drepper User Reference => ud-puts-overflow
2009-10-29 18:21 drepper Section => puts()
2009-10-29 18:21 drepper Page Number => 1723
2009-10-29 18:21 drepper Line Number => 55058
2009-10-29 18:30 nick Tag Attached: c99
2009-10-29 18:32 nick Note Added: 0000271
2009-10-29 21:09 cmsmith Note Added: 0000272
2009-10-29 22:58 drepper Note Added: 0000273
2009-10-30 09:51 geoffclare Note Added: 0000274
2009-11-12 16:38 msbrown Interp Status => ---
2009-11-12 16:38 msbrown Note Added: 0000298
2009-11-12 16:38 msbrown Status Under Review => Resolved
2009-11-12 16:38 msbrown Resolution Open => Accepted As Marked
2009-11-12 16:39 msbrown Final Accepted Text => Note: 0000298
2010-08-27 13:05 ajosey Tag Attached: tc1-2008


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker