Add upstream patch fixing usage of errno in json_parse_uint64()
This commit is contained in:
parent
cbe7c2bdbe
commit
deea28a0b0
74
json-c-0.14-fix_usage_of_errno_in_json_parse_uint64.patch
Normal file
74
json-c-0.14-fix_usage_of_errno_in_json_parse_uint64.patch
Normal file
@ -0,0 +1,74 @@
|
||||
From 003b58782b12798da3da8b952152988a88dfb532 Mon Sep 17 00:00:00 2001
|
||||
From: Pierce Lopez <pierce.lopez@gmail.com>
|
||||
Date: Sun, 10 May 2020 13:20:02 -0400
|
||||
Subject: [PATCH] fix json_parse_uint64() usage of errno
|
||||
|
||||
introduced in #542
|
||||
fixes #601
|
||||
---
|
||||
json_util.c | 8 +++-----
|
||||
json_util.h | 1 +
|
||||
tests/test_parse_int64.expected | 8 ++++----
|
||||
3 files changed, 8 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/json_util.c b/json_util.c
|
||||
index d3ee47df72..e8e2ec6bcb 100644
|
||||
--- a/json_util.c
|
||||
+++ b/json_util.c
|
||||
@@ -245,19 +245,17 @@ int json_parse_uint64(const char *buf, uint64_t *retval)
|
||||
{
|
||||
char *end = NULL;
|
||||
uint64_t val;
|
||||
- errno = 1;
|
||||
|
||||
+ errno = 0;
|
||||
while (*buf == ' ')
|
||||
- {
|
||||
buf++;
|
||||
- }
|
||||
if (*buf == '-')
|
||||
- errno = 0;
|
||||
+ return 1; /* error: uint cannot be negative */
|
||||
|
||||
val = strtoull(buf, &end, 10);
|
||||
if (end != buf)
|
||||
*retval = val;
|
||||
- return ((errno == 0) || (end == buf)) ? 1 : 0;
|
||||
+ return ((val == 0 && errno != 0) || (end == buf)) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifndef HAVE_REALLOC
|
||||
diff --git a/json_util.h b/json_util.h
|
||||
index 2a4b6c19bd..7520f036c4 100644
|
||||
--- a/json_util.h
|
||||
+++ b/json_util.h
|
||||
@@ -100,6 +100,7 @@ JSON_EXPORT int json_object_to_fd(int fd, struct json_object *obj, int flags);
|
||||
*/
|
||||
JSON_EXPORT const char *json_util_get_last_err(void);
|
||||
|
||||
+/* these parsing helpers return zero on success */
|
||||
JSON_EXPORT int json_parse_int64(const char *buf, int64_t *retval);
|
||||
JSON_EXPORT int json_parse_uint64(const char *buf, uint64_t *retval);
|
||||
JSON_EXPORT int json_parse_double(const char *buf, double *retval);
|
||||
diff --git a/tests/test_parse_int64.expected b/tests/test_parse_int64.expected
|
||||
index f4c5750b0b..6dca94b470 100644
|
||||
--- a/tests/test_parse_int64.expected
|
||||
+++ b/tests/test_parse_int64.expected
|
||||
@@ -34,13 +34,13 @@ buf=123 parseit=0, value=123
|
||||
==========json_parse_uint64() test===========
|
||||
buf=x parseit=1, value=666
|
||||
buf=0 parseit=0, value=0
|
||||
-buf=-0 parseit=1, value=0
|
||||
+buf=-0 parseit=1, value=666
|
||||
buf=00000000 parseit=0, value=0
|
||||
-buf=-00000000 parseit=1, value=0
|
||||
+buf=-00000000 parseit=1, value=666
|
||||
buf=1 parseit=0, value=1
|
||||
buf=2147483647 parseit=0, value=2147483647
|
||||
-buf=-1 parseit=1, value=18446744073709551615
|
||||
-buf=-9223372036854775808 parseit=1, value=9223372036854775808
|
||||
+buf=-1 parseit=1, value=666
|
||||
+buf=-9223372036854775808 parseit=1, value=666
|
||||
buf= 1 parseit=0, value=1
|
||||
buf=00001234 parseit=0, value=1234
|
||||
buf=0001234x parseit=0, value=1234
|
@ -26,7 +26,7 @@
|
||||
|
||||
Name: json-c
|
||||
Version: 0.14
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
Summary: JSON implementation in C
|
||||
|
||||
License: MIT
|
||||
@ -36,6 +36,7 @@ Source0: %{url}/archive/%{name}-%{version}-%{reldate}.tar.gz
|
||||
# Cherry-picked from upstream.
|
||||
Patch0001: %{url}/commit/228881c8fc287182f284a58d8279a32fbeae0b7f.patch#/%{name}-0.14-dont_install_config_h.patch
|
||||
Patch0002: %{url}/pull/603.patch#/%{name}-0.14-backport_fixes_from_master.patch
|
||||
Patch0003: %{url}/commit/003b58782b12798da3da8b952152988a88dfb532.patch#/%{name}-0.14-fix_usage_of_errno_in_json_parse_uint64.patch
|
||||
|
||||
BuildRequires: cmake
|
||||
BuildRequires: gcc
|
||||
@ -132,6 +133,9 @@ popd
|
||||
|
||||
|
||||
%changelog
|
||||
* Mon May 11 2020 Björn Esser <besser82@fedoraproject.org> - 0.14-3
|
||||
- Add upstream patch fixing usage of errno in json_parse_uint64()
|
||||
|
||||
* Sun May 10 2020 Björn Esser <besser82@fedoraproject.org> - 0.14-2
|
||||
- Add a patch to backport fixes applied on upstream master branch
|
||||
- Re-enable RDRAND as json-c can detect broken implementations in CPUs now
|
||||
|
Loading…
Reference in New Issue
Block a user