* [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix
@ 2015-01-27 16:13 Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 1/3] util/uri: uri_new() can't fail, drop dead error handling Markus Armbruster
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Markus Armbruster @ 2015-01-27 16:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Note: checkpatch is unhappy with the first patch, because I refrained
from cleaning up the ugly return(NULL). They're all over the place.
Markus Armbruster (3):
util/uri: uri_new() can't fail, drop dead error handling
util/uri: realloc2n() can't fail, drop dead error handling
util/uri: URI member path can be null, compare more carfully
util/uri.c | 61 +++++++++++++------------------------------------------------
1 file changed, 13 insertions(+), 48 deletions(-)
--
1.9.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 1/3] util/uri: uri_new() can't fail, drop dead error handling
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
@ 2015-01-27 16:13 ` Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 2/3] util/uri: realloc2n() " Markus Armbruster
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Markus Armbruster @ 2015-01-27 16:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
util/uri.c | 36 +++++++++++-------------------------
1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/util/uri.c b/util/uri.c
index 918d235..aa39694 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -928,12 +928,10 @@ uri_parse(const char *str) {
if (str == NULL)
return(NULL);
uri = uri_new();
- if (uri != NULL) {
- ret = rfc3986_parse_uri_reference(uri, str);
- if (ret) {
- uri_free(uri);
- return(NULL);
- }
+ ret = rfc3986_parse_uri_reference(uri, str);
+ if (ret) {
+ uri_free(uri);
+ return(NULL);
}
return(uri);
}
@@ -974,15 +972,13 @@ uri_parse_raw(const char *str, int raw) {
if (str == NULL)
return(NULL);
uri = uri_new();
- if (uri != NULL) {
- if (raw) {
- uri->cleanup |= 2;
- }
- ret = uri_parse_into(uri, str);
- if (ret) {
- uri_free(uri);
- return(NULL);
- }
+ if (raw) {
+ uri->cleanup |= 2;
+ }
+ ret = uri_parse_into(uri, str);
+ if (ret) {
+ uri_free(uri);
+ return(NULL);
}
return(uri);
}
@@ -1675,8 +1671,6 @@ uri_resolve(const char *uri, const char *base) {
else {
if (*uri) {
ref = uri_new();
- if (ref == NULL)
- goto done;
ret = uri_parse_into(ref, uri);
}
else
@@ -1695,8 +1689,6 @@ uri_resolve(const char *uri, const char *base) {
ret = -1;
else {
bas = uri_new();
- if (bas == NULL)
- goto done;
ret = uri_parse_into(bas, base);
}
if (ret != 0) {
@@ -1727,8 +1719,6 @@ uri_resolve(const char *uri, const char *base) {
* document.
*/
res = uri_new();
- if (res == NULL)
- goto done;
if ((ref->scheme == NULL) && (ref->path == NULL) &&
((ref->authority == NULL) && (ref->server == NULL))) {
res->scheme = g_strdup(bas->scheme);
@@ -1933,8 +1923,6 @@ uri_resolve_relative (const char *uri, const char * base)
* First parse URI into a standard form
*/
ref = uri_new ();
- if (ref == NULL)
- return NULL;
/* If URI not already in "relative" form */
if (uri[0] != '.') {
ret = uri_parse_into (ref, uri);
@@ -1951,8 +1939,6 @@ uri_resolve_relative (const char *uri, const char * base)
goto done;
}
bas = uri_new ();
- if (bas == NULL)
- goto done;
if (base[0] != '.') {
ret = uri_parse_into (bas, base);
if (ret != 0)
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 2/3] util/uri: realloc2n() can't fail, drop dead error handling
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 1/3] util/uri: uri_new() can't fail, drop dead error handling Markus Armbruster
@ 2015-01-27 16:13 ` Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 3/3] util/uri: URI member path can be null, compare more carfully Markus Armbruster
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Markus Armbruster @ 2015-01-27 16:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
util/uri.c | 22 ----------------------
1 file changed, 22 deletions(-)
diff --git a/util/uri.c b/util/uri.c
index aa39694..b9a7b54 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -1049,14 +1049,12 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = *p++;
}
if (len >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = ':';
@@ -1066,7 +1064,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
@@ -1083,7 +1080,6 @@ uri_to_string(URI *uri) {
if (uri->server != NULL) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '/';
@@ -1093,7 +1089,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
if ((IS_UNRESERVED(*(p))) ||
@@ -1112,7 +1107,6 @@ uri_to_string(URI *uri) {
}
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '@';
@@ -1121,7 +1115,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = *p++;
@@ -1129,7 +1122,6 @@ uri_to_string(URI *uri) {
if (uri->port > 0) {
if (len + 10 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
len += snprintf(&ret[len], max - len, ":%d", uri->port);
@@ -1137,7 +1129,6 @@ uri_to_string(URI *uri) {
} else if (uri->authority != NULL) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '/';
@@ -1146,7 +1137,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
if ((IS_UNRESERVED(*(p))) ||
@@ -1165,7 +1155,6 @@ uri_to_string(URI *uri) {
} else if (uri->scheme != NULL) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '/';
@@ -1185,7 +1174,6 @@ uri_to_string(URI *uri) {
(!strcmp(uri->scheme, "file"))) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = *p++;
@@ -1195,7 +1183,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
@@ -1215,7 +1202,6 @@ uri_to_string(URI *uri) {
if (uri->query != NULL) {
if (len + 1 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '?';
@@ -1223,7 +1209,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 1 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = *p++;
@@ -1233,7 +1218,6 @@ uri_to_string(URI *uri) {
if (uri->fragment != NULL) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len++] = '#';
@@ -1241,7 +1225,6 @@ uri_to_string(URI *uri) {
while (*p != 0) {
if (len + 3 >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
@@ -1257,15 +1240,10 @@ uri_to_string(URI *uri) {
}
if (len >= max) {
temp = realloc2n(ret, &max);
- if (temp == NULL) goto mem_error;
ret = temp;
}
ret[len] = 0;
return(ret);
-
-mem_error:
- g_free(ret);
- return(NULL);
}
/**
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH 3/3] util/uri: URI member path can be null, compare more carfully
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 1/3] util/uri: uri_new() can't fail, drop dead error handling Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 2/3] util/uri: realloc2n() " Markus Armbruster
@ 2015-01-27 16:13 ` Markus Armbruster
2015-01-27 16:43 ` [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Paolo Bonzini
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Markus Armbruster @ 2015-01-27 16:13 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Paolo Bonzini
uri_resolve_relative() calls strcmp(bas->path, ref->path). However,
either argument could be null! Evidence: the code checks for null
after the comparison. Spotted by Coverity.
I suspect this was screwed up when we stole the code from libxml2.
There the conditional reads
xmlStrEqual((xmlChar *)bas->path, (xmlChar *)ref->path)
with
int
xmlStrEqual(const xmlChar *str1, const xmlChar *str2) {
if (str1 == str2) return(1);
if (str1 == NULL) return(0);
if (str2 == NULL) return(0);
do {
if (*str1++ != *str2) return(0);
} while (*str2++);
return(1);
}
Fix by replicating libxml2's logic faithfully.
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
util/uri.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/util/uri.c b/util/uri.c
index b9a7b54..1cfd78b 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -1935,7 +1935,8 @@ uri_resolve_relative (const char *uri, const char * base)
val = g_strdup (uri);
goto done;
}
- if (!strcmp(bas->path, ref->path)) {
+ if (bas->path == ref->path ||
+ (bas->path && ref->path && !strcmp(bas->path, ref->path))) {
val = g_strdup("");
goto done;
}
--
1.9.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
` (2 preceding siblings ...)
2015-01-27 16:13 ` [Qemu-devel] [PATCH 3/3] util/uri: URI member path can be null, compare more carfully Markus Armbruster
@ 2015-01-27 16:43 ` Paolo Bonzini
2015-01-28 11:21 ` Markus Armbruster
2015-02-04 9:48 ` Markus Armbruster
2015-02-07 20:43 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
5 siblings, 1 reply; 9+ messages in thread
From: Paolo Bonzini @ 2015-01-27 16:43 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: qemu-trivial
On 27/01/2015 17:13, Markus Armbruster wrote:
> Note: checkpatch is unhappy with the first patch, because I refrained
> from cleaning up the ugly return(NULL). They're all over the place.
>
> Markus Armbruster (3):
> util/uri: uri_new() can't fail, drop dead error handling
> util/uri: realloc2n() can't fail, drop dead error handling
> util/uri: URI member path can be null, compare more carfully
>
> util/uri.c | 61 +++++++++++++------------------------------------------------
> 1 file changed, 13 insertions(+), 48 deletions(-)
>
Patches 1-2 okay. For patch 3 a very similar patch was posted yesterday.
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix
2015-01-27 16:43 ` [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Paolo Bonzini
@ 2015-01-28 11:21 ` Markus Armbruster
2015-01-28 13:30 ` Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Markus Armbruster @ 2015-01-28 11:21 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-trivial, qemu-devel
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 27/01/2015 17:13, Markus Armbruster wrote:
>> Note: checkpatch is unhappy with the first patch, because I refrained
>> from cleaning up the ugly return(NULL). They're all over the place.
>>
>> Markus Armbruster (3):
>> util/uri: uri_new() can't fail, drop dead error handling
>> util/uri: realloc2n() can't fail, drop dead error handling
>> util/uri: URI member path can be null, compare more carfully
>>
>> util/uri.c | 61 +++++++++++++------------------------------------------------
>> 1 file changed, 13 insertions(+), 48 deletions(-)
>>
>
> Patches 1-2 okay. For patch 3 a very similar patch was posted yesterday.
Missed it until now. Yes, it's functionally identical.
Dear -trivial maintainer, pick whichever you like better :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix
2015-01-28 11:21 ` Markus Armbruster
@ 2015-01-28 13:30 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2015-01-28 13:30 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-trivial, qemu-devel
On 28/01/2015 12:21, Markus Armbruster wrote:
>> > Patches 1-2 okay. For patch 3 a very similar patch was posted yesterday.
> Missed it until now. Yes, it's functionally identical.
>
> Dear -trivial maintainer, pick whichever you like better :)
Sure -- Markus's is nicer indeed.
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
` (3 preceding siblings ...)
2015-01-27 16:43 ` [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Paolo Bonzini
@ 2015-02-04 9:48 ` Markus Armbruster
2015-02-07 20:43 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
5 siblings, 0 replies; 9+ messages in thread
From: Markus Armbruster @ 2015-02-04 9:48 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial
Ping?
Markus Armbruster <armbru@redhat.com> writes:
> Note: checkpatch is unhappy with the first patch, because I refrained
> from cleaning up the ugly return(NULL). They're all over the place.
>
> Markus Armbruster (3):
> util/uri: uri_new() can't fail, drop dead error handling
> util/uri: realloc2n() can't fail, drop dead error handling
> util/uri: URI member path can be null, compare more carfully
>
> util/uri.c | 61 +++++++++++++------------------------------------------------
> 1 file changed, 13 insertions(+), 48 deletions(-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [Qemu-trivial] [PATCH 0/3] util/uri: Cleanups and a bug fix
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
` (4 preceding siblings ...)
2015-02-04 9:48 ` Markus Armbruster
@ 2015-02-07 20:43 ` Michael Tokarev
5 siblings, 0 replies; 9+ messages in thread
From: Michael Tokarev @ 2015-02-07 20:43 UTC (permalink / raw)
To: Markus Armbruster, qemu-devel; +Cc: qemu-trivial
27.01.2015 19:13, Markus Armbruster wrote:
> Note: checkpatch is unhappy with the first patch, because I refrained
> from cleaning up the ugly return(NULL). They're all over the place.
>
> Markus Armbruster (3):
> util/uri: uri_new() can't fail, drop dead error handling
> util/uri: realloc2n() can't fail, drop dead error handling
> util/uri: URI member path can be null, compare more carfully
Applied all to -trivial, with patch 3 replacing similar patch by Paolo.
Thanks,
/mjt
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-02-07 20:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-27 16:13 [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 1/3] util/uri: uri_new() can't fail, drop dead error handling Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 2/3] util/uri: realloc2n() " Markus Armbruster
2015-01-27 16:13 ` [Qemu-devel] [PATCH 3/3] util/uri: URI member path can be null, compare more carfully Markus Armbruster
2015-01-27 16:43 ` [Qemu-devel] [PATCH 0/3] util/uri: Cleanups and a bug fix Paolo Bonzini
2015-01-28 11:21 ` Markus Armbruster
2015-01-28 13:30 ` Paolo Bonzini
2015-02-04 9:48 ` Markus Armbruster
2015-02-07 20:43 ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.