From: Mark Hatle <mark.hatle@kernel.crashing.org>
To: yocto-patches@lists.yoctoproject.org
Cc: seebs@seebs.net, richard.purdie@linuxfoundation.org
Subject: [pseudo][PATCH 17/20] makewrappers: improve error handling and robustness
Date: Thu, 15 Jan 2026 17:43:33 -0600 [thread overview]
Message-ID: <1768520616-7289-18-git-send-email-mark.hatle@kernel.crashing.org> (raw)
In-Reply-To: <1768520616-7289-1-git-send-email-mark.hatle@kernel.crashing.org>
From: Mark Hatle <mark.hatle@amd.com>
Add several robustness improvements to the makewrappers Python script:
* Add null checks for self.type and arg.name to prevent AttributeError
when processing malformed function declarations
* Add validation for comment format to ensure '=' is present before
attempting to parse comments into dictionaries
* Replace incorrect poll() calls with returncode attribute when
checking subprocess completion status
* Add proper file error handling with context managers (with statements)
and OSError exceptions when reading/writing wrapper files
* Add argument validation to ensure wrapper function arguments are
properly specified before generating code
These changes prevent crashes when processing invalid input and improve
error reporting when file operations fail.
AI-Generated: Suggested by GitHub Copilot (Claude Sonnet 4.5)
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
makewrappers | 73 ++++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 33 deletions(-)
diff --git a/makewrappers b/makewrappers
index c9f6ad5..326f70e 100755
--- a/makewrappers
+++ b/makewrappers
@@ -12,7 +12,6 @@ import sys
import re
import os.path
import platform
-import string
import subprocess
from templatefile import TemplateFile
@@ -152,9 +151,11 @@ class Argument:
# spacing between type and name, needed if type ends with a character
# which could be part of an identifier
- if re.match('[_a-zA-Z0-9]', self.type[-1]):
+ if self.type and re.match('[_a-zA-Z0-9]', self.type[-1]):
self.spacer = ' '
+ return
+
def decl(self, comment=False, wrap=False):
"""Produce the declaration form of this argument."""
if self.function_pointer:
@@ -274,13 +275,13 @@ class Function:
# ignore varargs, they never get these special treatments
if arg.vararg:
pass
- elif arg.name.endswith('dirfd'):
+ elif arg.name and arg.name.endswith('dirfd'):
if len(arg.name) > 5:
self.specific_dirfds[arg.name[:-5]] = True
self.dirfd = 'dirfd'
elif arg.name == 'flags':
self.flags = '(flags & AT_SYMLINK_NOFOLLOW)'
- elif arg.name.endswith('path'):
+ elif arg.name and arg.name.endswith('path'):
self.paths_to_munge.append(arg.name)
elif arg.name == 'fd':
self.fd_arg = "fd"
@@ -304,6 +305,10 @@ class Function:
# handle special comments, such as flags=AT_SYMLINK_NOFOLLOW
if self.comments:
comments = self.comments.replace('==','<equals>')
+ # Validate the comments
+ for mod in comments.split(','):
+ if '=' not in mod:
+ raise Exception("Parse error invalid comment '%s'" % (comments))
# Build a dictionary of key=value, key=value pairs
modifiers = dict(mod.split("=") for mod in comments.split(','))
# Strip all leading/trailing whitespace
@@ -535,7 +540,8 @@ additional ports to include.
if os.path.exists(self.portfile("preports")):
subport_proc = subprocess.Popen([self.portfile("preports"), self.name], stdout=subprocess.PIPE)
portlist = subport_proc.communicate()[0]
- retcode = subport_proc.poll()
+ portlist = portlist.decode("utf-8")
+ retcode = subport_proc.returncode
if retcode:
raise Exception("preports script failed for port %s" % self.name)
@@ -546,7 +552,8 @@ additional ports to include.
if os.path.exists(self.portfile("subports")):
subport_proc = subprocess.Popen([self.portfile("subports"), self.name], stdout=subprocess.PIPE)
portlist = subport_proc.communicate()[0]
- retcode = subport_proc.poll()
+ portlist = portlist.decode("utf-8")
+ retcode = subport_proc.returncode
if retcode:
raise Exception("subports script failed for port %s" % self.name)
@@ -622,20 +629,23 @@ def process_wrapfuncs(port):
funcs = {}
directory = os.path.dirname(filename)
sys.stdout.write("%s: " % filename)
- funclist = open(filename)
- for line in funclist:
- line = line.rstrip()
- if line.startswith('#') or not line:
- continue
- try:
- func = Function(port, line)
- func.directory = directory
- funcs[func.name] = func
- sys.stdout.write(".")
- except Exception as e:
- print("Parsing failed:", e)
- exit(1)
- funclist.close()
+ try:
+ with open(filename, "r") as funclist:
+ for line in funclist:
+ line = line.rstrip()
+ if line.startswith('#') or not line:
+ continue
+ try:
+ func = Function(port, line)
+ func.directory = directory
+ funcs[func.name] = func
+ sys.stdout.write(".")
+ except Exception as e:
+ print("Parsing failed:", e)
+ exit(1)
+ except OSError as e:
+ print("Unable to open file %s" % filename)
+ exit(1)
print("")
return funcs
@@ -645,13 +655,19 @@ def main(argv):
sources = []
for arg in argv:
+ if '=' not in arg:
+ print("Invalid argument '%s', must be of the form name=value" % arg)
+ exit(1)
name, value = arg.split('=')
os.environ["port_" + name] = value
# error checking helpfully provided by the exception handler
- copyright_file = open('guts/COPYRIGHT')
- TemplateFile.copyright = copyright_file.read()
- copyright_file.close()
+ try:
+ with open('guts/COPYRIGHT') as copyright_file:
+ TemplateFile.copyright = copyright_file.read()
+ except OSError as e:
+ print("Unable to open file guts/COPYRIGHT")
+ exit(1)
for path in glob.glob('templates/*'):
try:
@@ -665,16 +681,7 @@ def main(argv):
print("Invalid or malformed template %s. Aborting." % path)
exit(1)
- try:
- port = Port('common', sources)
-
- except KeyError:
- print("Unknown uname -s result: '%s'." % uname_s)
- print("Known system types are:")
- print("%-20s %-10s %s" % ("uname -s", "port name", "description"))
- for key in host_ports:
- print("%-20s %-10s %s" % (key, host_ports[key],
- host_descrs[host_ports[key]]))
+ port = Port('common', sources)
# the per-function stuff
print("Writing functions...")
--
2.43.0
next prev parent reply other threads:[~2026-01-15 23:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 23:43 [pseudo][PATCH 00/20] Consolidated pseudo patches Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 01/20] test-syscall: Remove build warning Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 02/20] test: Cleanup test output Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 03/20] test/test-statx.sh: It should be a failure if pseudo prints an error Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 04/20] test-realpath: Verify the realpath behavior matches glibc Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 05/20] run_tests.sh: In verbose mode, include pseudo.log in output Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 06/20] test/test-statx: Add uutils test case Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 07/20] test/test-nftw: Avoid compile warnings Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 08/20] test-tclsh-fork: Skip test if tclsh is not available Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 09/20] ports/unix/guts/realpath.c: realpath fails if the resolved path doesn't exist Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 10/20] test/test-proc-pipe.sh: Add test case for proc pipes Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 11/20] pseudo_util.c: Skip realpath like expansion for /proc on Linux Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 12/20] ports/unix/guts/realpath.c: Fix indents Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 13/20] ports/linux/pseudo_wrappers.c: Reorder the syscall operations Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 14/20] ports/linux/pseudo_wrappers.c: Call the wrappers where possible Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 15/20] ports/linux: Add additional EFAULTS for Linux functions Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 16/20] Update COPYRIGHT files Mark Hatle
2026-01-15 23:43 ` Mark Hatle [this message]
2026-01-15 23:43 ` [pseudo][PATCH 18/20] pseudo: code quality scan - resolved various potential issues Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 19/20] configure: Minor code quality changes Mark Hatle
2026-01-15 23:43 ` [pseudo][PATCH 20/20] Makefile.in: Bump version to 1.9.3 Mark Hatle
[not found] ` <188B0C23901378A4.2703508@lists.yoctoproject.org>
2026-01-17 16:08 ` [yocto-patches] [pseudo][PATCH 13/20] ports/linux/pseudo_wrappers.c: Reorder the syscall operations Mark Hatle
[not found] ` <188B0C2348C47D4E.2703508@lists.yoctoproject.org>
2026-01-17 16:10 ` [yocto-patches] [pseudo][PATCH 15/20] ports/linux: Add additional EFAULTS for Linux functions Mark Hatle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1768520616-7289-18-git-send-email-mark.hatle@kernel.crashing.org \
--to=mark.hatle@kernel.crashing.org \
--cc=richard.purdie@linuxfoundation.org \
--cc=seebs@seebs.net \
--cc=yocto-patches@lists.yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.