From 6f884e1f0464237646f3bd87917bee90f95b617f Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Sat, 2 May 2015 01:25:51 +0200 Subject: [PATCH] Fix potential name truncation in merge_ns() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It seems I misread the snprintf man page: a return value of exactly the buffer size means truncation has occurred, so we need to fix the operator (`>` → `≥`). Additionally, improve slightly the error message raised in such a case; this shouldn't ever happen. --- xattr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xattr.c b/xattr.c index b0fdb77..980796c 100644 --- a/xattr.c +++ b/xattr.c @@ -182,9 +182,9 @@ static int merge_ns(const char *ns, const char *name, return -1; } cnt = snprintf(*buf, new_size, "%s.%s", ns, name); - if((size_t) cnt > new_size || cnt < 0) { + if((size_t) cnt >= new_size || cnt < 0) { PyErr_SetString(PyExc_ValueError, - "can't format the attribute name"); + "unexpected: can't format the attribute name"); PyMem_Free(*buf); return -1; } -- 2.39.2