In _snprintf() functions definition the buffer is null terminated.
Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
{
int ret, remain = size, offset = 0;
+ if (size)
+ buf[0] = '\0';
+
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
int nftnl_chain_snprintf(char *buf, size_t size, const struct nftnl_chain *c,
uint32_t type, uint32_t flags)
{
- return nftnl_chain_cmd_snprintf(buf, size, c, nftnl_flag2cmd(flags), type,
- flags);
+ if (size)
+ buf[0] = '\0';
+
+ return nftnl_chain_cmd_snprintf(buf, size, c, nftnl_flag2cmd(flags),
+ type, flags);
}
EXPORT_SYMBOL(nftnl_chain_snprintf);
static int nftnl_chain_do_snprintf(char *buf, size_t size, const void *c,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_chain_snprintf(buf, size, c, type, flags);
}
int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
NFTNL_BUF_INIT(b, buf, size);
if (cmd == NFTNL_CMD_UNSPEC)
int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
NFTNL_BUF_INIT(b, buf, size);
if (cmd == NFTNL_CMD_UNSPEC)
int ret;
unsigned int offset = 0, remain = size;
+ if (size)
+ buf[0] = '\0';
+
if (!expr->ops->snprintf)
return 0;
nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_bitwise_snprintf_default(buf, size, e);
nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_byteorder_snprintf_default(buf, size, e);
nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_cmp_snprintf_default(buf, size, e);
uint32_t flags,
const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_counter_snprintf_default(buf, len, e);
nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_ct_snprintf_default(buf, len, e);
uint32_t output_format, uint32_t flags,
int reg_type)
{
+ if (size)
+ buf[0] = '\0';
+
switch(reg_type) {
case DATA_VALUE:
switch(output_format) {
static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_exthdr_snprintf_default(buf, len, e);
nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_fib_snprintf_default(buf, len, e);
static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_hash_snprintf_default(buf, len, e);
nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_limit_snprintf_default(buf, len, e);
nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_log_snprintf_default(buf, len, e);
nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_masq_snprintf_default(buf, len, e);
{
struct nftnl_expr_match *match = nftnl_expr_data(e);
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return snprintf(buf, len, "name %s rev %u ",
nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_meta_snprintf_default(buf, len, e);
nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_nat_snprintf_default(buf, size, e);
nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_ng_snprintf_default(buf, len, e);
uint32_t flags,
const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_objref_snprintf_default(buf, len, e);
{
struct nftnl_expr_payload *payload = nftnl_expr_data(e);
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
if (payload->sreg)
nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
uint32_t flags,
const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_quota_snprintf_default(buf, len, e);
static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_range_snprintf_default(buf, size, e);
nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_redir_snprintf_default(buf, len, e);
nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_reject_snprintf_default(buf, len, e);
nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_rt_snprintf_default(buf, len, e);
{
struct nftnl_expr_target *target = nftnl_expr_data(e);
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return snprintf(buf, len, "name %s rev %u ",
{
int ret, remain = size, offset = 0;
+ if (size)
+ buf[0] = '\0';
+
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
int nftnl_gen_snprintf(char *buf, size_t size, const struct nftnl_gen *gen,
uint32_t type, uint32_t flags)
-{;
+{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_gen_cmd_snprintf(buf, size, gen, nftnl_flag2cmd(flags), type,
flags);
}
static int nftnl_gen_do_snprintf(char *buf, size_t size, const void *gen,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf = '\0';
+
return nftnl_gen_snprintf(buf, size, gen, type, flags);
}
uint32_t flags,
const struct nftnl_obj *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_obj_counter_snprintf_default(buf, len, e);
uint32_t flags,
const struct nftnl_obj *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_obj_ct_helper_snprintf_default(buf, len, e);
uint32_t flags,
const struct nftnl_obj *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_obj_limit_snprintf_default(buf, len, e);
uint32_t flags,
const struct nftnl_obj *e)
{
+ if (len)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_obj_quota_snprintf_default(buf, len, e);
{
int ret, remain = size, offset = 0;
+ if (size)
+ buf[0] = '\0';
+
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
int nftnl_obj_snprintf(char *buf, size_t size, const struct nftnl_obj *obj,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_obj_cmd_snprintf(buf, size, obj, nftnl_flag2cmd(flags),
type, flags);
}
static int nftnl_obj_do_snprintf(char *buf, size_t size, const void *obj,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_obj_snprintf(buf, size, obj, type, flags);
}
int ret, remain = size, offset = 0;
uint32_t inner_flags = flags;
+ if (size)
+ buf[0] = '\0';
+
inner_flags &= ~NFTNL_OF_EVENT_ANY;
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
int nftnl_rule_snprintf(char *buf, size_t size, const struct nftnl_rule *r,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_rule_cmd_snprintf(buf, size, r, nftnl_flag2cmd(flags), type,
flags);
}
static int nftnl_rule_do_snprintf(char *buf, size_t size, const void *r,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_rule_snprintf(buf, size, r, type, flags);
}
void *prev = NULL;
uint32_t inner_flags = flags;
+ if (size)
+ buf[0] = '\0';
+
/* dont pass events flags to child calls of _snprintf() */
inner_flags &= ~NFTNL_OF_EVENT_ANY;
const struct nftnl_ruleset *r, uint32_t cmd,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
case NFTNL_OUTPUT_JSON:
int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
case NFTNL_OUTPUT_JSON:
if (type == NFTNL_OUTPUT_XML)
return 0;
+ if (size)
+ buf[0] = '\0';
+
/* prevent set_elems to print as events */
inner_flags &= ~NFTNL_OF_EVENT_ANY;
int nftnl_set_snprintf(char *buf, size_t size, const struct nftnl_set *s,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_set_cmd_snprintf(buf, size, s, nftnl_flag2cmd(flags), type,
flags);
}
static int nftnl_set_do_snprintf(char *buf, size_t size, const void *s,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_set_snprintf(buf, size, s, type, flags);
}
if (type == NFTNL_OUTPUT_XML)
return 0;
+ if (size)
+ buf[0] = '\0';
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
const struct nftnl_set_elem *e,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_set_elem_cmd_snprintf(buf, size, e, nftnl_flag2cmd(flags),
type, flags);
}
uint32_t cmd, uint32_t type,
uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_set_elem_snprintf(buf, size, e, type, flags);
}
{
int ret, remain = size, offset = 0;
+ if (size)
+ buf[0] = '\0';
+
ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
int nftnl_table_snprintf(char *buf, size_t size, const struct nftnl_table *t,
uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_table_cmd_snprintf(buf, size, t, nftnl_flag2cmd(flags), type,
flags);
}
static int nftnl_table_do_snprintf(char *buf, size_t size, const void *t,
uint32_t cmd, uint32_t type, uint32_t flags)
{
+ if (size)
+ buf[0] = '\0';
+
return nftnl_table_snprintf(buf, size, t, type, flags);
}