summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/cooker.py
diff options
context:
space:
mode:
authorJoshua Watt <JPEWhacker@gmail.com>2024-10-08 13:36:25 +0100
committerSteve Sakoman <steve@sakoman.com>2024-12-06 05:50:24 -0800
commitd77302b2fe94db6c132310771b7b97c7b534edec (patch)
tree9dfca5b2686eb7a96d6c53e4920502a0581efed4 /bitbake/lib/bb/cooker.py
parentfd5231a5445f0a61d3a7678d1980a94dc1c80544 (diff)
downloadpoky-d77302b2fe94db6c132310771b7b97c7b534edec.tar.gz
bitbake: Remove custom exception backtrace formatting
Removes the code in bitbake to show custom backtrace formatting for exceptions. In particular, the bitbake exception code prints function arguments, which while helpful is a security problem when passwords and other secrets can be passed as function arguments. As it turns out, the handling of the custom serialized exception stack frames was pretty much made obsolete by d7db75020ed ("event/msg: Pass formatted exceptions"), which changed the events to pass a preformatted stacktrack list of strings, but the passing of the serialized data was never removed. Change all the code to use the python traceback API to format exceptions instead of the custom code; conveniently traceback.format_exception() also returns a list of stack trace strings, so it can be used as a drop in replacement for bb.exception.format_exception() (Bitbake rev: c25e7ed128b9fd5b53d28d678238e2f3af52ef8b) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r--bitbake/lib/bb/cooker.py32
1 files changed, 24 insertions, 8 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 6318ef4a8f..1cb3e189f4 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -17,7 +17,7 @@ import threading
17from io import StringIO, UnsupportedOperation 17from io import StringIO, UnsupportedOperation
18from contextlib import closing 18from contextlib import closing
19from collections import defaultdict, namedtuple 19from collections import defaultdict, namedtuple
20import bb, bb.exceptions, bb.command 20import bb, bb.command
21from bb import utils, data, parse, event, cache, providers, taskdata, runqueue, build 21from bb import utils, data, parse, event, cache, providers, taskdata, runqueue, build
22import queue 22import queue
23import signal 23import signal
@@ -2097,7 +2097,6 @@ class Parser(multiprocessing.Process):
2097 except Exception as exc: 2097 except Exception as exc:
2098 tb = sys.exc_info()[2] 2098 tb = sys.exc_info()[2]
2099 exc.recipe = filename 2099 exc.recipe = filename
2100 exc.traceback = list(bb.exceptions.extract_traceback(tb, context=3))
2101 return True, None, exc 2100 return True, None, exc
2102 # Need to turn BaseExceptions into Exceptions here so we gracefully shutdown 2101 # Need to turn BaseExceptions into Exceptions here so we gracefully shutdown
2103 # and for example a worker thread doesn't just exit on its own in response to 2102 # and for example a worker thread doesn't just exit on its own in response to
@@ -2298,8 +2297,12 @@ class CookerParser(object):
2298 return False 2297 return False
2299 except ParsingFailure as exc: 2298 except ParsingFailure as exc:
2300 self.error += 1 2299 self.error += 1
2301 logger.error('Unable to parse %s: %s' % 2300
2302 (exc.recipe, bb.exceptions.to_string(exc.realexception))) 2301 exc_desc = str(exc)
2302 if isinstance(exc, SystemExit) and not isinstance(exc.code, str):
2303 exc_desc = 'Exited with "%d"' % exc.code
2304
2305 logger.error('Unable to parse %s: %s' % (exc.recipe, exc_desc))
2303 self.shutdown(clean=False) 2306 self.shutdown(clean=False)
2304 return False 2307 return False
2305 except bb.parse.ParseError as exc: 2308 except bb.parse.ParseError as exc:
@@ -2308,20 +2311,33 @@ class CookerParser(object):
2308 self.shutdown(clean=False, eventmsg=str(exc)) 2311 self.shutdown(clean=False, eventmsg=str(exc))
2309 return False 2312 return False
2310 except bb.data_smart.ExpansionError as exc: 2313 except bb.data_smart.ExpansionError as exc:
2314 def skip_frames(f, fn_prefix):
2315 while f and f.tb_frame.f_code.co_filename.startswith(fn_prefix):
2316 f = f.tb_next
2317 return f
2318
2311 self.error += 1 2319 self.error += 1
2312 bbdir = os.path.dirname(__file__) + os.sep 2320 bbdir = os.path.dirname(__file__) + os.sep
2313 etype, value, _ = sys.exc_info() 2321 etype, value, tb = sys.exc_info()
2314 tb = list(itertools.dropwhile(lambda e: e.filename.startswith(bbdir), exc.traceback)) 2322
2323 # Remove any frames where the code comes from bitbake. This
2324 # prevents deep (and pretty useless) backtraces for expansion error
2325 tb = skip_frames(tb, bbdir)
2326 cur = tb
2327 while cur:
2328 cur.tb_next = skip_frames(cur.tb_next, bbdir)
2329 cur = cur.tb_next
2330
2315 logger.error('ExpansionError during parsing %s', value.recipe, 2331 logger.error('ExpansionError during parsing %s', value.recipe,
2316 exc_info=(etype, value, tb)) 2332 exc_info=(etype, value, tb))
2317 self.shutdown(clean=False) 2333 self.shutdown(clean=False)
2318 return False 2334 return False
2319 except Exception as exc: 2335 except Exception as exc:
2320 self.error += 1 2336 self.error += 1
2321 etype, value, tb = sys.exc_info() 2337 _, value, _ = sys.exc_info()
2322 if hasattr(value, "recipe"): 2338 if hasattr(value, "recipe"):
2323 logger.error('Unable to parse %s' % value.recipe, 2339 logger.error('Unable to parse %s' % value.recipe,
2324 exc_info=(etype, value, exc.traceback)) 2340 exc_info=sys.exc_info())
2325 else: 2341 else:
2326 # Most likely, an exception occurred during raising an exception 2342 # Most likely, an exception occurred during raising an exception
2327 import traceback 2343 import traceback