Skip to content

Commit da3fc1e

Browse files
committed
Fix NULL pointer reference when closing an unused multi handle.
1 parent 85a2e9e commit da3fc1e

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

lib/multi.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,10 +1773,12 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle)
17731773
/* Close all the connections in the connection cache */
17741774
close_all_connections(multi);
17751775

1776-
multi->closure_handle->dns.hostcache = multi->hostcache;
1777-
Curl_hostcache_clean(multi->closure_handle);
1776+
if(multi->closure_handle) {
1777+
multi->closure_handle->dns.hostcache = multi->hostcache;
1778+
Curl_hostcache_clean(multi->closure_handle);
17781779

1779-
Curl_close(multi->closure_handle);
1780+
Curl_close(multi->closure_handle);
1781+
}
17801782
multi->closure_handle = NULL;
17811783

17821784
Curl_hash_destroy(multi->sockhash);

tests/data/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ test1387 test1388 test1389 test1390 test1391 test1392 test1393 \
9494
test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
9595
test1408 test1409 test1410 test1411 test1412 test1413 \
9696
test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
97+
test1508 \
9798
test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
9899
test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
99100
test2016 test2017 test2018 test2019 test2020 test2021 test2022 \

tests/data/test1508

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<testcase>
2+
<info>
3+
<keywords>
4+
HTTP
5+
multi
6+
</keywords>
7+
</info>
8+
9+
# Client-side
10+
<client>
11+
<server>
12+
none
13+
</server>
14+
<tool>
15+
lib1508
16+
</tool>
17+
<name>
18+
Close a multi handle without using it
19+
</name>
20+
<command>
21+
http://%HOSTIP:%HTTPPORT/path/1508
22+
</command>
23+
</client>
24+
25+
# Verify data after the test has been "shot"
26+
<verify>
27+
<file name="log/stdout1508" mode="text">
28+
We are done
29+
</file>
30+
</verify>
31+
</testcase>

tests/libtest/Makefile.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
2323
lib582 lib583 lib585 lib586 lib587 \
2424
lib590 lib591 lib597 lib598 lib599 \
2525
\
26-
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507
26+
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508
2727

2828
chkhostname_SOURCES = chkhostname.c ../../lib/curl_gethostname.c
2929
chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -316,3 +316,7 @@ lib1506_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1506
316316
lib1507_SOURCES = lib1507.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
317317
lib1507_LDADD = $(TESTUTIL_LIBS)
318318
lib1507_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1507
319+
320+
lib1508_SOURCES = lib1508.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
321+
lib1508_LDADD = $(TESTUTIL_LIBS)
322+
lib1508_CPPFLAGS = $(AM_CPPFLAGS) -DLIB1508

tests/libtest/lib1508.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/***************************************************************************
2+
* _ _ ____ _
3+
* Project ___| | | | _ \| |
4+
* / __| | | | |_) | |
5+
* | (__| |_| | _ <| |___
6+
* \___|\___/|_| \_\_____|
7+
*
8+
* Copyright (C) 2013, Linus Nielsen Feltzing <linus@haxx.se>
9+
*
10+
* This software is licensed as described in the file COPYING, which
11+
* you should have received as part of this distribution. The terms
12+
* are also available at http://curl.haxx.se/docs/copyright.html.
13+
*
14+
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
15+
* copies of the Software, and permit persons to whom the Software is
16+
* furnished to do so, under the terms of the COPYING file.
17+
*
18+
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19+
* KIND, either express or implied.
20+
*
21+
***************************************************************************/
22+
#include "test.h"
23+
24+
#include "testutil.h"
25+
#include "warnless.h"
26+
#include "memdebug.h"
27+
28+
int test(char *URL)
29+
{
30+
int res = 0;
31+
CURLM *m = NULL;
32+
33+
(void)URL;
34+
35+
global_init(CURL_GLOBAL_ALL);
36+
37+
multi_init(m);
38+
39+
test_cleanup:
40+
41+
/* proper cleanup sequence - type PB */
42+
43+
curl_multi_cleanup(m);
44+
curl_global_cleanup();
45+
46+
printf("We are done\n");
47+
48+
return res;
49+
}

0 commit comments

Comments
 (0)