return j;
}
+/**
+ * mutt_buffer_quote_filename - Quote a filename to survive the shell's quoting rules
+ * @param buf Buffer for the result
+ * @param filename String to convert
+ * @retval num Bytes written to the buffer
+ */
+void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename)
+{
+ if (!buf || !filename)
+ return;
+
+ mutt_buffer_reset(buf);
+ mutt_buffer_addch(buf, '\'');
+
+ for (; *filename != '\0'; filename++)
+ {
+ if ((*filename == '\'') || (*filename == '`'))
+ {
+ mutt_buffer_addch(buf, '\'');
+ mutt_buffer_addch(buf, '\\');
+ mutt_buffer_addch(buf, *filename);
+ mutt_buffer_addch(buf, '\'');
+ }
+ else
+ mutt_buffer_addch(buf, *filename);
+ }
+
+ mutt_buffer_addch(buf, '\'');
+}
+
/**
* mutt_file_mkdir - Recursively create directories
* @param path Directories to create
void mutt_file_unlink_empty(const char *path);
int mutt_file_unlock(int fd);
+void mutt_buffer_quote_filename(struct Buffer *buf, const char *filename);
+
#endif /* MUTT_LIB_FILE_H */
*/
void pgp_class_invoke_import(const char *fname)
{
- char tmp_fname[PATH_MAX + 128];
char cmd[STR_COMMAND];
struct PgpCommandContext cctx = { 0 };
- mutt_file_quote_filename(fname, tmp_fname, sizeof(tmp_fname));
- cctx.fname = tmp_fname;
+ struct Buffer *buf_fname = mutt_buffer_pool_get();
+
+ mutt_buffer_quote_filename(buf_fname, fname);
+ cctx.fname = mutt_b2s(buf_fname);
if (C_PgpSignAs && *C_PgpSignAs)
cctx.signas = C_PgpSignAs;
else
mutt_pgp_command(cmd, sizeof(cmd), &cctx, C_PgpImportCommand);
if (mutt_system(cmd) != 0)
mutt_debug(LL_DEBUG1, "Error running \"%s\"", cmd);
+
+ mutt_buffer_pool_release(&buf_fname);
}
/**
*/
void pgp_class_invoke_getkeys(struct Address *addr)
{
- char buf[PATH_MAX];
char tmp[1024];
char cmd[STR_COMMAND];
if (!C_PgpGetkeysCommand)
return;
+ struct Buffer *buf = mutt_buffer_pool_get();
personal = addr->personal;
addr->personal = NULL;
*tmp = '\0';
mutt_addrlist_to_local(addr);
mutt_addr_write_single(tmp, sizeof(tmp), addr, false);
- mutt_file_quote_filename(tmp, buf, sizeof(buf));
+ mutt_buffer_quote_filename(buf, tmp);
addr->personal = personal;
- cctx.ids = buf;
+ cctx.ids = mutt_b2s(buf);
mutt_pgp_command(cmd, sizeof(cmd), &cctx, C_PgpGetkeysCommand);
if (fd_null >= 0)
close(fd_null);
+
+ mutt_buffer_pool_release(&buf);
}
/**
int pgpinfd, int pgpoutfd, int pgperrfd,
enum PgpRing keyring, struct ListHead *hints)
{
- char quoted[STR_COMMAND];
-
struct Buffer *uids = mutt_buffer_pool_get();
+ struct Buffer *quoted = mutt_buffer_pool_get();
struct ListNode *np = NULL;
STAILQ_FOREACH(np, hints, entries)
{
- mutt_file_quote_filename((char *) np->data, quoted, sizeof(quoted));
- mutt_buffer_addstr(uids, quoted);
+ mutt_buffer_quote_filename(quoted, (char *) np->data);
+ mutt_buffer_addstr(uids, mutt_b2s(quoted));
if (STAILQ_NEXT(np, entries))
mutt_buffer_addch(uids, ' ');
}
C_PgpListPubringCommand);
mutt_buffer_pool_release(&uids);
+ mutt_buffer_pool_release("ed);
return rc;
}
{
if (!optional)
{
- char path[PATH_MAX];
- char buf1[1024], buf2[1024];
+ struct Buffer *path = mutt_buffer_pool_get();
+ struct Buffer *buf1 = mutt_buffer_pool_get();
+ struct Buffer *buf2 = mutt_buffer_pool_get();
struct stat sb;
- mutt_str_strfcpy(path, C_SmimeCaLocation, sizeof(path));
- mutt_expand_path(path, sizeof(path));
- mutt_file_quote_filename(path, buf1, sizeof(buf1));
+ mutt_buffer_strcpy(path, C_SmimeCaLocation);
+ mutt_buffer_expand_path(path);
+ mutt_buffer_quote_filename(buf1, mutt_b2s(path));
- if ((stat(path, &sb) != 0) || !S_ISDIR(sb.st_mode))
- snprintf(buf2, sizeof(buf2), "-CAfile %s", buf1);
+ if ((stat(mutt_b2s(path), &sb) != 0) || !S_ISDIR(sb.st_mode))
+ mutt_buffer_printf(buf2, "-CAfile %s", mutt_b2s(buf1));
else
- snprintf(buf2, sizeof(buf2), "-CApath %s", buf1);
+ mutt_buffer_printf(buf2, "-CApath %s", mutt_b2s(buf1));
snprintf(fmt, sizeof(fmt), "%%%ss", prec);
- snprintf(buf, buflen, fmt, buf2);
+ snprintf(buf, buflen, fmt, mutt_b2s(buf2));
+
+ mutt_buffer_pool_release(&path);
+ mutt_buffer_pool_release(&buf1);
+ mutt_buffer_pool_release(&buf2);
}
else if (!C_SmimeCaLocation)
optional = 0;
*/
int mix_send_message(struct ListHead *chain, const char *tempfile)
{
- char cd_quoted[256];
int i = 0;
-
struct Buffer *cmd = mutt_buffer_pool_get();
+ struct Buffer *cd_quoted = mutt_buffer_pool_get();
+
mutt_buffer_printf(cmd, "cat %s | %s -m ", tempfile, C_Mixmaster);
struct ListNode *np = NULL;
STAILQ_FOREACH(np, chain, entries)
{
mutt_buffer_addstr(cmd, i ? "," : " -l ");
- mutt_file_quote_filename(np->data, cd_quoted, sizeof(cd_quoted));
- mutt_buffer_addstr(cmd, cd_quoted);
+ mutt_buffer_quote_filename(cd_quoted, (char *) np->data);
+ mutt_buffer_addstr(cmd, mutt_b2s(cd_quoted));
i = 1;
}
}
mutt_buffer_pool_release(&cmd);
+ mutt_buffer_pool_release(&cd_quoted);
unlink(tempfile);
return i;
}
int rfc1524_expand_command(struct Body *a, const char *filename,
const char *type, char *command, int clen)
{
- int x = 0, y = 0;
+ int x = 0;
int needspipe = true;
- char buf[STR_COMMAND];
char type2[1024];
+ struct Buffer *buf = mutt_buffer_pool_get();
+ struct Buffer *quoted = mutt_buffer_pool_get();
mutt_str_strfcpy(type2, type, sizeof(type2));
if (C_MailcapSanitize)
mutt_file_sanitize_filename(type2, false);
- while ((x < clen - 1) && command[x] && (y < sizeof(buf) - 1))
+ while ((x < clen - 1) && command[x])
{
if (command[x] == '\\')
{
x++;
- buf[y++] = command[x++];
+ mutt_buffer_addch(buf, command[x++]);
}
else if (command[x] == '%')
{
if (C_MailcapSanitize)
mutt_file_sanitize_filename(pvalue, false);
- y += mutt_file_quote_filename(pvalue, buf + y, sizeof(buf) - y);
+ mutt_buffer_quote_filename(quoted, pvalue);
+ mutt_buffer_addstr(buf, mutt_b2s(quoted));
}
else if ((command[x] == 's') && filename)
{
- y += mutt_file_quote_filename(filename, buf + y, sizeof(buf) - y);
+ mutt_buffer_quote_filename(quoted, filename);
+ mutt_buffer_addstr(buf, mutt_b2s(quoted));
needspipe = false;
}
else if (command[x] == 't')
{
- y += mutt_file_quote_filename(type2, buf + y, sizeof(buf) - y);
+ mutt_buffer_quote_filename(quoted, type);
+ mutt_buffer_addstr(buf, mutt_b2s(quoted));
}
x++;
}
else
- buf[y++] = command[x++];
+ mutt_buffer_addch(buf, command[x++]);
}
- buf[y] = '\0';
- mutt_str_strfcpy(command, buf, clen);
+ mutt_str_strfcpy(command, mutt_b2s(buf), clen);
+
+ mutt_buffer_pool_release(&buf);
+ mutt_buffer_pool_release("ed);
return needspipe;
}