[Bug 2540] New: Adds xstrndup() to xmalloc.h/xmalloc.c in OpenSSH 7.x
bugzilla-daemon at bugzilla.mindrot.org
bugzilla-daemon at bugzilla.mindrot.org
Sun Feb 14 08:30:39 AEDT 2016
https://bugzilla.mindrot.org/show_bug.cgi?id=2540
Bug ID: 2540
Summary: Adds xstrndup() to xmalloc.h/xmalloc.c in OpenSSH 7.x
Product: Portable OpenSSH
Version: 7.1p1
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P5
Component: Miscellaneous
Assignee: unassigned-bugs at mindrot.org
Reporter: wp02855 at gmail.com
Created attachment 2785
--> https://bugzilla.mindrot.org/attachment.cgi?id=2785&action=edit
patch file for this bug report
Hello All,
The code below implements the C function 'strndup()' in
xmalloc.h
and xmalloc.c (for future use, if needed):
--- xmalloc.h.orig 2016-02-13 09:15:50.418982399 -0800
+++ xmalloc.h 2016-02-13 09:16:24.760347010 -0800
@@ -20,6 +20,7 @@
void *xcalloc(size_t, size_t);
void *xreallocarray(void *, size_t, size_t);
char *xstrdup(const char *);
+char *xstrndup(const char *, size_t);
int xasprintf(char **, const char *, ...)
__attribute__((__format__ (printf, 2, 3)))
__attribute__((__nonnull__ (2)));
=======================================================================
--- xmalloc.c.orig 2016-02-13 09:33:10.108121542 -0800
+++ xmalloc.c 2016-02-13 09:34:07.203378056 -0800
@@ -79,6 +79,20 @@
return cp;
}
+char *
+xstrndup(const char *str, size_t dst_size)
+{
+ char *cp;
+ size_t len;
+
+ len = strlen(str) + 1;
+ if (len > size)
+ len = size + 1;
+ cp = xmalloc(len);
+ strlcpy(cp, str, len);
+ return cp;
+}
+
int
xasprintf(char **ret, const char *fmt, ...)
{
======================================================================
I am attaching the patch file(s) to this report...
Bill Parker (wp02855 at gmail dot com)
--
You are receiving this mail because:
You are watching the assignee of the bug.
More information about the openssh-bugs
mailing list