Merge pull request #1953 from N-R-K/fix-fortify-abortion

fix crash under _FORTIFY_SOURCE
This commit is contained in:
Arun 2024-11-12 10:17:12 +05:30 committed by GitHub
commit 9db87a782c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2834,15 +2834,16 @@ static char *get_archive_cmd(const char *archive)
static void archive_selection(const char *cmd, const char *archive) static void archive_selection(const char *cmd, const char *archive)
{ {
char *buf = malloc((xstrlen(patterns[P_ARCHIVE_CMD]) + xstrlen(cmd) + xstrlen(archive) size_t len = xstrlen(patterns[P_ARCHIVE_CMD]) + xstrlen(cmd) + xstrlen(archive)
+ xstrlen(selpath)) * sizeof(char)); + xstrlen(selpath) + 1;
char *buf = malloc(len);
if (!buf) { if (!buf) {
DPRINTF_S(strerror(errno)); DPRINTF_S(strerror(errno));
printwarn(NULL); printwarn(NULL);
return; return;
} }
snprintf(buf, CMD_LEN_MAX, patterns[P_ARCHIVE_CMD], cmd, archive, selpath); snprintf(buf, len, patterns[P_ARCHIVE_CMD], cmd, archive, selpath);
spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI | F_CONFIRM); spawn(utils[UTIL_SH_EXEC], buf, NULL, NULL, F_CLI | F_CONFIRM);
free(buf); free(buf);
} }