cURL / Mailing Lists / curl-library / Single Mail

curl-library

idiot-proofing getinfo

From: David McCreedy <mccreedytpf_at_msn.com>
Date: Fri, 22 Dec 2006 01:33:14 +0000

A co-worked told me about libcurl dumps he was seeing from Curl_get_info.
On further research it turned out to be an inadvertently NULLed CURL handle
he was passing to the function.
He was surprised there were "null pointer" checks in the function and asked
me to submit a patch.

I don't know what the forum's philosophy is on these types of safety checks.
Should we implement a check or let the caller pay the price for their coding
errors?

My patch (attached and below) tries to make getinfo at least
idiot-resistant, in case the decision is to add the check.

Thanks,

-David

--- curl-7.16.1-20061221/lib/getinfo.c 2006-09-24 22:00:22.000000000 -0400
+++ curlinux/lib/getinfo.c 2006-12-21 17:59:27.407182000 -0500
@@ -104,6 +104,18 @@
     break;
   }

+ /* safeguard against a null CURL handle */
+ switch(info) {
+ default:
+ /* most options require a CURL handle */
+ if(!data)
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ break;
+ case CURLINFO_SSL_ENGINES:
+ /* option is OK with a null CURL handle, no need to check it */
+ break;
+ }
+
   switch(info) {
   case CURLINFO_EFFECTIVE_URL:
     *param_charp = data->change.url?data->change.url:(char *)"";

Received on 2006-12-22