a549770045e50e58829388cf0bf0b615fc44db89
[openwrt/staging/nbd.git] /
1 From e1c6b35f9f978f6919e8bf651de67b30dc145543 Mon Sep 17 00:00:00 2001
2 From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
3 Date: Sun, 18 Mar 2018 08:51:08 +0000
4 Subject: [PATCH] iproute2: fix hidden uint to uin64_t promotion in json_print
5
6 print_int used 'int' type internally, whereas print_uint used 'uint64_t'
7
8 These helper functions eventually call vfprintf(fp, fmt, args) which is
9 a variable argument list function and is dependent upon 'fmt' containing
10 correct information about the length of the passed arguments.
11
12 Unfortunately print_int v print_uint offered no clue to the programmer
13 that internally passed ints to print_uint were being promoted to 64bits,
14 thus the format passed in 'fmt' string vs the actual passed integer
15 could be different lengths. This is even more interesting on big endian
16 architectures where 'vfprintf' would be looking in the middle of an
17 int64 type. Symptoms of this included tc qdisc showing bizarre values
18 for a variety of fields across a variety of qdiscs (e.g. refcnt, flows,
19 quantum)
20
21 print_u/int now stick with native int size.
22
23 A similar patch has been sent upstream.
24
25 Fixes FS#1425
26
27 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
28 ---
29 include/json_print.h | 2 +-
30 lib/json_print.c | 2 +-
31 2 files changed, 2 insertions(+), 2 deletions(-)
32
33 diff --git a/include/json_print.h b/include/json_print.h
34 index dc4d2bb3..350d35cb 100644
35 --- a/include/json_print.h
36 +++ b/include/json_print.h
37 @@ -56,10 +56,10 @@ void close_json_array(enum output_type type, const char *delim);
38 print_color_##type_name(t, COLOR_NONE, key, fmt, value); \
39 }
40 _PRINT_FUNC(int, int);
41 +_PRINT_FUNC(uint, unsigned int);
42 _PRINT_FUNC(bool, bool);
43 _PRINT_FUNC(null, const char*);
44 _PRINT_FUNC(string, const char*);
45 -_PRINT_FUNC(uint, uint64_t);
46 _PRINT_FUNC(hu, unsigned short);
47 _PRINT_FUNC(hex, unsigned int);
48 _PRINT_FUNC(0xhex, unsigned int);
49 diff --git a/lib/json_print.c b/lib/json_print.c
50 index aa527af6..ae3a317d 100644
51 --- a/lib/json_print.c
52 +++ b/lib/json_print.c
53 @@ -117,8 +117,8 @@ void close_json_array(enum output_type type, const char *str)
54 } \
55 }
56 _PRINT_FUNC(int, int);
57 +_PRINT_FUNC(uint, unsigned int);
58 _PRINT_FUNC(hu, unsigned short);
59 -_PRINT_FUNC(uint, uint64_t);
60 _PRINT_FUNC(lluint, unsigned long long int);
61 #undef _PRINT_FUNC
62
63 --
64 2.14.3 (Apple Git-98)
65