Bug 1691347 - Work around a null argument bug in _platform_strstr in CUPS. r=dholbert
commitc286431b9a2ab406aa19833f9df24fc4e8605b7d
authorEmily McDonough <emcdonough@mozilla.com>
Fri, 22 Oct 2021 22:55:25 +0000 (22 22:55 +0000)
committerEmily McDonough <emcdonough@mozilla.com>
Fri, 22 Oct 2021 22:55:25 +0000 (22 22:55 +0000)
tree5606152a8b47186bd8e19bbd146f0858803b3bb7
parentd5dbd9115b46b53f29a3cd2767ccdef009a3e10f
Bug 1691347 - Work around a null argument bug in _platform_strstr in CUPS. r=dholbert

This is just a large conditional to check for the specific branches taken
that would result in the null string. The path in CUPS is as follows:

In cupsCopyDestInfo, CUPS_DEST_FLAG_DEVICE is set when the connection is not
null (same as CUPS_HTTP_DEFAULT), the print server is not the same as our
hostname and is not path-based (starts with a '/'), or the IPP port is
different than the global server IPP port.

https://github.com/apple/cups/blob/c9da6f63b263faef5d50592fe8cf8056e0a58aa2/cups/dest-options.c#L718-L722

In _cupsGetDestResource, CUPS fetches the IPP options "printer-uri-supported"
and "device-uri". Importantly, IPP options are returned as null when missing.

https://github.com/apple/cups/blob/23c45db76a8520fd6c3b1d9164dbe312f1ab1481/cups/dest.c#L1138-L1141

If the CUPS_DEST_FLAG_DEVICE is set or the "printer-uri-supported" option is
not set, CUPS checks for "._tcp" in the "device-uri" option without doing a
NULL-check first.

https://github.com/apple/cups/blob/23c45db76a8520fd6c3b1d9164dbe312f1ab1481/cups/dest.c#L1144

If we find that those branches will be taken, don't actually fetch the CUPS
data and instead just return an empty printer info.

Differential Revision: https://phabricator.services.mozilla.com/D128529
widget/nsCUPSShim.h
widget/nsPrinterCUPS.cpp
widget/nsPrinterCUPS.h