From 60374ee737a54737c84ce87a466edbf6457dbbda Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 29 Oct 2019 22:52:48 +0800 Subject: [PATCH] cpdup(1): Check the return value of asprintf() and exit if fails See also: https://github.com/DragonFlyBSD/cpdup/commit/90aee43e060104e974f623924c3dfc0a4359ceb5 Reported by GCC 9.x on Arch Linux. --- bin/cpdup/cpdup.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/cpdup/cpdup.c b/bin/cpdup/cpdup.c index e596428be2..60fc7a5f7c 100644 --- a/bin/cpdup/cpdup.c +++ b/bin/cpdup/cpdup.c @@ -613,7 +613,8 @@ checkHLPath(struct stat *st1, const char *spath, const char *dpath) char *hpath; int error; - asprintf(&hpath, "%s%s", UseHLPath, dpath + DstBaseLen); + if (asprintf(&hpath, "%s%s", UseHLPath, dpath + DstBaseLen) < 0) + fatal("out of memory"); /* * stat info matches ? @@ -1647,7 +1648,8 @@ CheckList(List *list, const char *path, const char *name) Node *node; int hv; - asprintf(&fpath, "%s/%s", path, name); + if (asprintf(&fpath, "%s/%s", path, name) < 0) + fatal("out of memory"); /* * Scan against wildcards. Only a node value of 1 can be a wildcard -- 2.41.0