View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002014 | 1003.1(2024)/Issue8 | System Interfaces | public | 2026-11-29 15:18 | 2026-11-29 23:11 |
| Reporter | romanzilka | Assigned To | |||
| Priority | low | Severity | Editorial | Type | Enhancement Request |
| Status | New | Resolution | Open | ||
| Name | Roman Žilka | ||||
| Organization | |||||
| User Reference | |||||
| Section | strerror_r, string.h | ||||
| Page Number | 0 | ||||
| Line Number | 0 | ||||
| Interp Status | |||||
| Final Accepted Text | |||||
| Summary | 0002014: strerror_r(): Error message length limit | ||||
| Description | As shown in issue 2013, strerror_r() may be the only feasible means of obtaining an error string. The string may have an arbitrary size, however, so if an application wants to ensure that the full string is obtained, a loop is required, which re-reallocates the target buffer, if it isn't large enough. And there's no guarantee that any particular size will be sufficient. Moreover, the function is extremely useful when combined with a buffer on the stack. The proposal doesn't impose a direct length cap on the error string, instead allowing the implementation to space-optimize by setting the length cap itself, within bounds. For consistency, the limit is imposed on all the strerror*() functions. | ||||
| Desired Action | 1. In the Description in the section on strerror_r(), just after the sentence segment: "otherwise, if these functions complete successfully, the message string shall indicate that an unknown error occurred." add the sentence (inside [CX]): "The message string provided by these functions shall be at most STRERR_SIZE bytes large." 2. In the Description in the section on string.h add the sentence: "The <string.h> header shall define the macro STRERR_SIZE, which expands to a positive integer denoting the maximum size in bytes of the error string returned by strerror(), strerror_l() and strerror_r(). STRERR_SIZE shall not be greater than 256 * MB_LEN_MAX, as defined in <limits.h>." | ||||
| Tags | No tags attached. | ||||
|
|
The submitter's description reads > The string may have an arbitrary size and > there's no guarantee that any particular size will be sufficient. I believe the current text of the standard disagrees with these statements. In Issue 8, lines 69377-69378 read > NAME > strerror, strerror_l, strerror_r — get error message string This affirms that any string returned by any of these functions is a "message string", and lines 10242-10243 ["XBD Headers — <limits.h>"] reads as > # Other Invariant Values > The <limits.h> header shall define the following symbolic constants: > {NL_TEXTMAX} > Maximum number of bytes in a message string. Therefore, I believe the NL_TEXTMAX constant already offers the functionality described by the submitter's STRERR_SIZE, as an upper bound on the length of a string returned by strerror() and friends. Defining this constant with a meaningful value is required, and it must be at least _POSIX2_LINE_MAX. As it is an invariant value, applications never need to use sysconf() to obtain this constant's value. However, the submitter is correct to point out that this may not be appropriate to allocate a buffer automatically ("on the stack"), as NL_TEXTMAX can be arbitrarily large (in the GNU C Library, for example, it's equivalent to INT32_MAX). Although I don't speak for any vendor or implementation, I am concerned that imposing a fixed absolute bound on a string that can be returned by strerror() and friends will adversely affect internationalization, including an implementation's ability to accommodate additional languages or charmaps that may be configured by an administrator. The reality that NL_TEXTMAX may be very large is something applications, perhaps, need to tolerate: dynamic allocation in some fashion may be inevitable to accommodate these systems. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-29 15:18 | romanzilka | New Issue | |
| 2026-11-29 23:09 | jscott0 | Note Added: 0007570 | |
| 2026-11-29 23:11 | jscott0 | Note Edited: 0007570 |