Anonymous | Login | 2024-12-02 07:01 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0001019 | [1003.1(2013)/Issue7+TC1] System Interfaces | Editorial | Clarification Requested | 2016-01-05 14:46 | 2024-06-11 08:58 | ||
Reporter | ch3root | View Status | public | ||||
Assigned To | |||||||
Priority | normal | Resolution | Accepted As Marked | ||||
Status | Closed | ||||||
Name | Alexander Cherepanov | ||||||
Organization | |||||||
User Reference | |||||||
Section | strndup | ||||||
Page Number | 2012 | ||||||
Line Number | 64214-64220 | ||||||
Interp Status | --- | ||||||
Final Accepted Text | Note: 0003471 | ||||||
Summary | 0001019: strndup shouldn't require source array to be null-terminated | ||||||
Description |
The description of the strndup function in POSIX talks about the array argument s as a C string. E.g., it's assumed to have length: "If the length of s is larger than size, only size bytes shall be duplicated." This poses two problems: 1) it's impossible to use strndup to duplicate a non-null-terminated array of a given size; 2) it gives to implementations freedom to examine more than size bytes of the array pointed to by s which could complicate a situation in multithreading program or when restricted pointers are involved. A quite natural way to implement strndup is by using strnlen. Then those problems don't arise. This is the case for at least glibc[1], musl[2] and OpenBSD[3]/FreeBSD[4]. NetBSD[5] is similar. Such a treatment of its argument causes strndup to differ from other strn* functions which don't have these problem. Take for example the strncat function (which copies one of its arguments too): "The strncat() function shall append not more than n bytes (a NUL character and bytes that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1." While the destination s1 is described as a string the source s2 is only described as an array. And there are no mentions of the length of s2. Rightly so. [1] https://sourceware.org/git/?p=glibc.git;a=blob;f=string/strndup.c;h=51a1969146df7b911e761706f7dece6dc149c7dd;hb=HEAD [^] [2] http://git.musl-libc.org/cgit/musl/tree/src/string/strndup.c [^] [3] http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/string/strndup.c?rev=1.2&content-type=text/x-cvsweb-markup [^] [4] https://svnweb.freebsd.org/base/head/lib/libc/string/strndup.c?revision=287181&view=markup [^] [5] http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/string/strndup.c?rev=1.4&content-type=text/x-cvsweb-markup&only_with_tag=MAIN [^] |
||||||
Desired Action |
Formulate the description of strndup in terms of arrays instead of strings to make it similar to other strn* function. Make it clear that the strndup function shall never examine more than maxlen bytes of the array pointed to by s (like strnlen). |
||||||
Tags | tc3-2008 | ||||||
Attached Files | |||||||
|
Relationships | |||||||
|
Issue History | |||
Date Modified | Username | Field | Change |
2016-01-05 14:46 | ch3root | New Issue | |
2016-01-05 14:46 | ch3root | Name | => Alexander Cherepanov |
2016-01-05 14:46 | ch3root | Section | => strndup |
2016-01-05 14:46 | ch3root | Page Number | => unknown |
2016-01-05 14:46 | ch3root | Line Number | => unknown |
2016-01-05 20:06 | Don Cragun | Page Number | unknown => 2012 |
2016-01-05 20:06 | Don Cragun | Line Number | unknown => 64214-64220 |
2016-01-05 20:06 | Don Cragun | Interp Status | => --- |
2016-01-05 20:14 | Don Cragun | Note Added: 0003002 | |
2016-01-05 20:28 | ch3root | Note Added: 0003003 | |
2016-01-05 21:05 | Don Cragun | Note Added: 0003004 | |
2016-01-05 22:10 | ch3root | Note Added: 0003005 | |
2016-01-05 23:31 | shware_systems | Note Added: 0003007 | |
2016-01-06 09:47 | ch3root | Note Added: 0003008 | |
2016-01-06 12:37 | kre | Note Added: 0003009 | |
2016-01-06 15:35 | shware_systems | Note Added: 0003012 | |
2016-01-07 10:25 | ch3root | Note Added: 0003015 | |
2016-01-07 20:40 | Florian Weimer | Issue Monitored: Florian Weimer | |
2016-10-27 16:15 | geoffclare | Note Added: 0003471 | |
2016-10-27 16:16 | geoffclare | Note Edited: 0003471 | |
2016-10-27 16:17 | geoffclare | Final Accepted Text | => Note: 0003471 |
2016-10-27 16:17 | geoffclare | Status | New => Resolved |
2016-10-27 16:17 | geoffclare | Resolution | Open => Accepted As Marked |
2016-10-27 16:17 | geoffclare | Tag Attached: tc3-2008 | |
2019-10-21 14:04 | geoffclare | Status | Resolved => Applied |
2020-09-01 08:31 | geoffclare | Relationship added | has duplicate 0001397 |
2024-06-11 08:58 | agadmin | Status | Applied => Closed |
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |