From 06061892698f227feb7babee95bc80400b2e6a85 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 12 Feb 2024 12:20:29 -0500 Subject: [PATCH] Make `parsePreRelease` copy the original string into a fixed width buffer so it avoids modifying the original string via `strntok` or similar --- semver.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/semver.c b/semver.c index 3b07e97..6bd24db 100644 --- a/semver.c +++ b/semver.c @@ -130,8 +130,12 @@ int parseGitRev(char *vp, GitRevision *git) { int parsePreRelease(PreRelease *pr, char *s) { PreReleaseTag tag; long val = 0; - char *vp; + char v[50]; + char *vp = (char *)v; + ssize_t len = strnlen(s, 52); + if (len > 50) return 1; + memcpy(s, vp, len); if (strncasecmp(s, "alpha", 5) == 0) { tag = Alpha; vp = s + 5;