[prev in list] [next in list] [prev in thread] [next in thread]
List: lxc-devel
Subject: [lxc-devel] [lxc/master] confile: improve strprint()
From: brauner on Github <lxc-bot () linuxcontainers ! org>
Date: 2018-05-30 13:41:32
Message-ID: 20180530134132.DCAC756F1A () mailman01 ! srv ! dcmtl ! stgraber ! net
[Download RAW message or body]
[Attachment #2 (text/x-mailbox)]
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2365
This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.
=== Description (from pull-request) ===
POSIX specifies [1]:
"If the value of n is zero on a call to snprintf(), nothing shall be written,
the number of bytes that would have been written had n been sufficiently large
excluding the terminating null shall be returned, and s may be a null pointer."
But in case there are any non-sane libcs out there that do actually dereference
the buffer when when 0 is passed as length to snprintf() let's give them a
dummy buffer.
[1]: The Open Group Base Specifications Issue 7, 2018 edition
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
Copyright © 2001-2018 IEEE and The Open Group
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
CC: Donghwa Jeong <dh48.jeong@samsung.com>
[Attachment #3 (text/plain)]
From 0e5be871954bff1724a6e568be0f9d2baef9e956 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner@ubuntu.com>
Date: Wed, 30 May 2018 15:34:03 +0200
Subject: [PATCH] confile: improve strprint()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
POSIX specifies [1]:
"If the value of n is zero on a call to snprintf(), nothing shall be written,
the number of bytes that would have been written had n been sufficiently large
excluding the terminating null shall be returned, and s may be a null pointer."
But in case there are any non-sane libcs out there that do actually dereference
the buffer when when 0 is passed as length to snprintf() let's give them a
dummy buffer.
[1]: The Open Group Base Specifications Issue 7, 2018 edition
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
Copyright © 2001-2018 IEEE and The Open Group
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
CC: Donghwa Jeong <dh48.jeong@samsung.com>
---
src/lxc/confile_utils.h | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h
index 072124f25..8fda5d798 100644
--- a/src/lxc/confile_utils.h
+++ b/src/lxc/confile_utils.h
@@ -41,21 +41,24 @@
#define MACVLAN_MODE_PASSTHRU 8
#endif
-#define strprint(str, inlen, ...) \
- do { \
- len = snprintf(str, inlen, ##__VA_ARGS__); \
- if (len < 0) { \
- SYSERROR("failed to create string"); \
- return -1; \
- }; \
- fulllen += len; \
- if (inlen > 0) { \
- if (str) \
- str += len; \
- inlen -= len; \
- if (inlen < 0) \
- inlen = 0; \
- } \
+#define strprint(str, inlen, ...) \
+ do { \
+ if (str) \
+ len = snprintf(str, inlen, ##__VA_ARGS__); \
+ else \
+ len = snprintf((char *){}, 0, ##__VA_ARGS__); \
+ if (len < 0) { \
+ SYSERROR("failed to create string"); \
+ return -1; \
+ }; \
+ fulllen += len; \
+ if (inlen > 0) { \
+ if (str) \
+ str += len; \
+ inlen -= len; \
+ if (inlen < 0) \
+ inlen = 0; \
+ } \
} while (0);
extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
[Attachment #4 (text/plain)]
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic