Enforce a limit on how many times smb_fdata() can recurse.
This fixes a stack exhaustion discovered by Include Security working
under the Mozilla SOS program in 2018 by means of code audit.
while (buf < maxbuf) {
const u_char *buf2;
depth++;
- buf2 = smb_fdata(ndo, buf, fmt, maxbuf, unicodestr);
+ /* Not sure how this relates with the protocol specification,
+ * but in order to avoid stack exhaustion recurse at most that
+ * many levels.
+ */
+ if (depth == 10)
+ ND_PRINT((ndo, "(too many nested levels, not recursing)"));
+ else
+ buf2 = smb_fdata(ndo, buf, fmt, maxbuf, unicodestr);
depth--;
if (buf2 == NULL)
return(NULL);