From de82134097b796a23321cc4024f46a238b5b1c4d Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Wed, 18 Apr 2007 03:03:51 +0300 Subject: [PATCH] readlink does not null-terminate its output. So we must do it ourselves. Signed-off-by: Michael S. Tsirkin --- mtcr.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mtcr.h b/mtcr.h index 4a1eee4..698a6d4 100644 --- a/mtcr.h +++ b/mtcr.h @@ -519,11 +519,13 @@ enum mtcr_access_method mtcr_parse_name(const char* name, int *force, goto parse_error; } - if (readlink(mbuf, pbuf, sizeof pbuf) < 0) { + tmp = readlink(mbuf, pbuf, sizeof pbuf - 1); + if (tmp < 0) { perror("read link"); fprintf(stderr,"Unable to read link %s\n", mbuf); return MTCR_ACCESS_ERROR; } + pbuf[tmp] = '0'; base = basename(pbuf); if (!base) -- 2.46.0