cregit-Linux how code gets into the kernel

Release 4.10 tools/perf/util/quote.c

Directory: tools/perf/util
#include <stdlib.h>
#include "strbuf.h"
#include "quote.h"
#include "util.h"

/* Help to copy the thing properly quoted for the shell safety.
 * any single quote is replaced with '\'', any exclamation point
 * is replaced with '\!', and the whole thing is enclosed in a
 *
 * E.g.
 *  original     sq_quote     result
 *  name     ==> name      ==> 'name'
 *  a b      ==> a b       ==> 'a b'
 *  a'b      ==> a'\''b    ==> 'a'\''b'
 *  a!b      ==> a'\!'b    ==> 'a'\!'b'
 */

static inline int need_bs_quote(char c) { return (c == '\'' || c == '!'); }

Contributors

PersonTokensPropCommitsCommitProp
ingo molnaringo molnar21100.00%1100.00%
Total21100.00%1100.00%


static int sq_quote_buf(struct strbuf *dst, const char *src) { char *to_free = NULL; int ret; if (dst->buf == src) to_free = strbuf_detach(dst, NULL); ret = strbuf_addch(dst, '\''); while (!ret && *src) { size_t len = strcspn(src, "'!"); ret = strbuf_add(dst, src, len); src += len; while (!ret && need_bs_quote(*src)) ret = strbuf_addf(dst, "'\\%c\'", *src++); } if (!ret) ret = strbuf_addch(dst, '\''); free(to_free); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
ingo molnaringo molnar10378.03%133.33%
masami hiramatsumasami hiramatsu2821.21%133.33%
arnaldo carvalho de meloarnaldo carvalho de melo10.76%133.33%
Total132100.00%3100.00%


int sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) { int i, ret; /* Copy into destination buffer. */ ret = strbuf_grow(dst, 255); for (i = 0; !ret && argv[i]; ++i) { ret = strbuf_addch(dst, ' '); if (ret) break; ret = sq_quote_buf(dst, argv[i]); if (maxlen && dst->len > maxlen) return -ENOSPC; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
ingo molnaringo molnar7275.00%133.33%
masami hiramatsumasami hiramatsu2020.83%133.33%
arnaldo carvalho de meloarnaldo carvalho de melo44.17%133.33%
Total96100.00%3100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
ingo molnaringo molnar20277.10%120.00%
masami hiramatsumasami hiramatsu4818.32%120.00%
arnaldo carvalho de meloarnaldo carvalho de melo124.58%360.00%
Total262100.00%5100.00%
Directory: tools/perf/util
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.