]> git.pld-linux.org Git - packages/jansson.git/blame - 0017-Fix-error-handling-in-json_pack.patch
0017-Fix-error-handling-in-json_pack.patch added
[packages/jansson.git] / 0017-Fix-error-handling-in-json_pack.patch
CommitLineData
9e72a0ef
JK
1From 15105b66b4df387037b670ac713584194ea10c2f Mon Sep 17 00:00:00 2001
2From: Maxim Zhukov <mussitantesmortem@gmail.com>
3Date: Mon, 12 Mar 2018 17:39:04 +0300
4Subject: [PATCH 17/22] Fix error handling in json_pack
5
6Changes to test/ removed.
7
8Fixed a bug where the error message was not filled if an empty object
9was passed to the json_pack.
10
11Fixes #271
12---
13 src/pack_unpack.c | 64 ++++++++++++++++++-------------------
14 test/suites/api/test_pack.c | 8 +++++
15 2 files changed, 40 insertions(+), 32 deletions(-)
16
17diff --git a/src/pack_unpack.c b/src/pack_unpack.c
18index 4026fd9..6461c06 100644
19--- a/src/pack_unpack.c
20+++ b/src/pack_unpack.c
21@@ -348,6 +348,36 @@ static json_t *pack_string(scanner_t *s, va_list *ap)
22 }
23 }
24
25+static json_t *pack_object_inter(scanner_t *s, va_list *ap, int need_incref)
26+{
27+ json_t *json;
28+ char ntoken;
29+
30+ next_token(s);
31+ ntoken = token(s);
32+
33+ if (ntoken != '?')
34+ prev_token(s);
35+
36+ json = va_arg(*ap, json_t *);
37+
38+ if (json)
39+ return need_incref ? json_incref(json) : json;
40+
41+ switch (ntoken) {
42+ case '?':
43+ return json_null();
44+ case '*':
45+ return NULL;
46+ default:
47+ break;
48+ }
49+
50+ set_error(s, "<args>", json_error_null_value, "NULL object key");
51+ s->has_error = 1;
52+ return NULL;
53+}
54+
55 static json_t *pack(scanner_t *s, va_list *ap)
56 {
57 switch(token(s)) {
58@@ -376,40 +406,10 @@ static json_t *pack(scanner_t *s, va_list *ap)
59 return json_real(va_arg(*ap, double));
60
61 case 'O': /* a json_t object; increments refcount */
62- {
63- int nullable;
64- json_t *json;
65-
66- next_token(s);
67- nullable = token(s) == '?';
68- if (!nullable)
69- prev_token(s);
70-
71- json = va_arg(*ap, json_t *);
72- if (!json && nullable) {
73- return json_null();
74- } else {
75- return json_incref(json);
76- }
77- }
78+ return pack_object_inter(s, ap, 1);
79
80 case 'o': /* a json_t object; doesn't increment refcount */
81- {
82- int nullable;
83- json_t *json;
84-
85- next_token(s);
86- nullable = token(s) == '?';
87- if (!nullable)
88- prev_token(s);
89-
90- json = va_arg(*ap, json_t *);
91- if (!json && nullable) {
92- return json_null();
93- } else {
94- return json;
95- }
96- }
97+ return pack_object_inter(s, ap, 0);
98
99 default:
100 set_error(s, "<format>", json_error_invalid_format, "Unexpected format character '%c'",
101--
1022.17.1
103
This page took 0.276701 seconds and 4 git commands to generate.