[libvirt] [PATCH] Allocate buffer to hold xend response
Jim Fehlig
jfehlig at novell.com
Fri Jun 4 16:19:01 UTC 2010
Jim Meyering wrote:
>> - if (VIR_ALLOC_N(*content, content_length) < 0 ) {
>> + if (content_length > XEND_RCV_BUF_MAX_LEN) {
>> + virXendError(VIR_ERR_INTERNAL_ERROR,
>> + _("Xend returned HTTP Content-Length of %d, "
>> + "which exceeds maximum of %d"),
>> + content_length,
>> + XEND_RCV_BUF_MAX_LEN);
>> + return -1;
>> + }
>> +
>>
>
> This is subtle enough that a comment might avoid trouble later.
>
> /* Allocate one byte beyond the end of the largest buffer we will read.
> Combined with the fact that VIR_ALLOC_N zeros the returned buffer,
> this guarantees that "content" will always be NUL-terminated. */
>
Good idea. I've added your wording verbatim.
>
>> + if (VIR_ALLOC_N(*content, content_length + 1) < 0 ) {
>> virReportOOMError();
>> return -1;
>> }
>> @@ -380,7 +390,7 @@ xend_get(virConnectPtr xend, const char *path,
>> virXendError(VIR_ERR_GET_FAILED,
>> _("%d status from xen daemon: %s:%s"),
>> ret, path,
>> - content ? *content: "NULL");
>> + content ? *content : "NULL");
>>
>
> Oh! I've just noticed that testing "content" is wrong,
> since it will always be non-NULL. BTW, the parameter should
> be marked as such via "ATTRIBUTE_NONNULL (3)".
>
I added ATTRIBUTE_NONNULL to xend_req() as well.
> The test should examine "*content", i.e.,
>
> *content ? *content : "NULL");
>
> Then I remembered the NULLSTR macro.
> You can replace the above with this:
>
> NULLSTR(*content));
>
>
> FYI, here's its definition:
>
> $ git grep -A2 ine.NULLSTR
> src/internal.h:# define NULLSTR(s) \
> src/internal.h- ((void)verify_true(sizeof *(s) == sizeof (char)), \
> src/internal.h- (s) ? (s) : "(null)")
>
Cool, that's handy. Updated patch attached.
Regards,
Jim
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixes-for-commit-211dd1e9.patch
Type: text/x-patch
Size: 2780 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100604/39b7fbda/attachment-0001.bin>
More information about the libvir-list
mailing list