]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
erec: use stdio vasprintf instead of gmp_vasprintf
authorSteven Barth <cyrus@openwrt.org>
Tue, 6 Jan 2015 22:40:24 +0000 (23:40 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 7 Jan 2015 12:08:43 +0000 (13:08 +0100)
Use stdio's vasprintf instead of gmp_vasprintf which is not part
of the mini-gmp function subset. Furthermore convert the only
gmp-specific user and allow the compiler to verify format-strings.

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/erec.c
src/evaluate.c

index 82543e6ddb3fc3e2d04ff8cb887391b7cbb2d18e..810e9bfdf41a75514990dabbccfb34325f9ec73d 100644 (file)
@@ -44,6 +44,7 @@ static void erec_destroy(struct error_record *erec)
        xfree(erec);
 }
 
+__attribute__((format(printf, 3, 0)))
 struct error_record *erec_vcreate(enum error_record_types type,
                                  const struct location *loc,
                                  const char *fmt, va_list ap)
@@ -55,10 +56,13 @@ struct error_record *erec_vcreate(enum error_record_types type,
        erec->num_locations     = 0;
        erec_add_location(erec, loc);
 
-       gmp_vasprintf(&erec->msg, fmt, ap);
+       if (vasprintf(&erec->msg, fmt, ap) < 0)
+               erec->msg = NULL;
+
        return erec;
 }
 
+__attribute__((format(printf, 3, 4)))
 struct error_record *erec_create(enum error_record_types type,
                                 const struct location *loc,
                                 const char *fmt, ...)
index 2c4e8116001be5eeec50a9a42875b5186349c5c0..43fb96811f626b90ba5218b9d805411917d15069 100644 (file)
@@ -232,9 +232,13 @@ static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
        case TYPE_INTEGER:
                mpz_init_bitmask(mask, ctx->ectx.len);
                if (mpz_cmp((*expr)->value, mask) > 0) {
+                       char *valstr = mpz_get_str(NULL, 10, (*expr)->value);
+                       char *rangestr = mpz_get_str(NULL, 10, mask);
                        expr_error(ctx->msgs, *expr,
-                                  "Value %Zu exceeds valid range 0-%Zu",
-                                  (*expr)->value, mask);
+                                  "Value %s exceeds valid range 0-%s",
+                                  valstr, rangestr);
+                       free(valstr);
+                       free(rangestr);
                        mpz_clear(mask);
                        return -1;
                }