Skip to content

Commit f99eb00

Browse files
committed
Fix pydoc null pointer dereference with missing arg type
Processing doxygen @param comments for a parameter whose name did not appear in the function declaration would cause a segfault due to a null pointer dereference. Adding test cases for both variadic function (no specified arguments) and @param comment that references an argument that is not named in the function prototype. Both of these cases previously segfaulted.
1 parent e4c38f0 commit f99eb00

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

Examples/test-suite/doxygen_basic_translate.i

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ double Atan2(double y, double x)
107107
return 0;
108108
}
109109

110+
/**
111+
* @brief Test variadic function
112+
* @param ... extra args
113+
*/
114+
void function8(...) {
115+
}
116+
117+
/**
118+
* @brief Test unnamed argument
119+
* @param baz Description of baz
120+
*/
121+
void function9(int) {
122+
}
123+
110124
/**
111125
* Comment at the end of file should be ignored.
112126
*/

Examples/test-suite/java/doxygen_basic_translate_runme.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ and calls the start() method of that class with parsed information.
9494
" @param x Horizontal coordinate.\n" +
9595
" @return Arc tangent of <code>y/x</code>.\n" +
9696
"");
97+
wantedComments.put("doxygen_basic_translate.doxygen_basic_translate.function8()",
98+
" Test variadic function\n" +
99+
"");
100+
101+
wantedComments.put("doxygen_basic_translate.doxygen_basic_translate.function9(int)",
102+
" Test unnamed argument\n" +
103+
"");
97104

98105
// and ask the parser to check comments for us
99106
System.exit(parser.check(wantedComments));

Examples/test-suite/python/doxygen_basic_translate_runme.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@
7070
:type a: :py:class:`Shape`
7171
:param a: Very strange param"""
7272
)
73+
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function8),
74+
"""\
75+
Test variadic function
76+
:param ...: extra args"""
77+
)
78+
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.function9),
79+
"""\
80+
Test unnamed argument
81+
:param baz: Description of baz"""
82+
)
7383

7484
comment_verifier.check(inspect.getdoc(doxygen_basic_translate.Atan2),
7585
"""\

Source/Doxygen/pydoc.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,10 @@ std::string PyDocConverter::getParamType(std::string param) {
418418
ParmList *plist = CopyParmList(Getattr(currentNode, "parms"));
419419
for (Parm *p = plist; p; p = nextSibling(p)) {
420420
String *pname = Getattr(p, "name");
421-
if (Char(pname) != param)
422-
continue;
423-
424-
type = getPyDocType(p, pname);
425-
break;
421+
if (pname && Char(pname) == param) {
422+
type = getPyDocType(p, pname);
423+
break;
424+
}
426425
}
427426
Delete(plist);
428427
return type;

0 commit comments

Comments
 (0)