Attention is currently required from: falconia.
pespin has posted comments on this change by falconia. ( https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email )
Change subject: osmo_iofd_register: fix the case of changing fd
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
@falcon@freecalypso.org can you share how did you notice this bug? did you see something failing somewhere?
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If8b8486ad7934afa203dfe1e996c9217373a017b
Gerrit-Change-Number: 39276
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: falconia <falcon(a)freecalypso.org>
Gerrit-Comment-Date: Thu, 09 Jan 2025 19:51:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: falconia.
pespin has posted comments on this change by falconia. ( https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email )
Change subject: osmo_iofd_register: fix the case of changing fd
......................................................................
Patch Set 1:
(2 comments)
Patchset:
PS1:
I think the proper fix is simply to add a line after the last "if" code path check:
"iofd->fd = fd;"
File src/core/osmo_io.c:
https://gerrit.osmocom.org/c/libosmocore/+/39276/comment/692a9e53_daf00168?… :
PS1, Line 756: else if (iofd->fd < 0)
I think you need to leave this as is. This code block basically makes sure that iofd->fd == fd if any of them was not set (-1).
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If8b8486ad7934afa203dfe1e996c9217373a017b
Gerrit-Change-Number: 39276
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: falconia <falcon(a)freecalypso.org>
Gerrit-Comment-Date: Thu, 09 Jan 2025 19:50:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: falconia.
pespin has posted comments on this change by falconia. ( https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email )
Change subject: osmo_iofd_register: fix the case of changing fd
......................................................................
Patch Set 1: Code-Review-1
(4 comments)
Commit Message:
https://gerrit.osmocom.org/c/libosmocore/+/39276/comment/c246cfbd_dba1f3ce?… :
PS1, Line 13: osmo_fd_setup(), or if it has changed since then, you can state
"or if it has changed since then" I probably missed that part when I caused the regression recently, thanks for noticing.
https://gerrit.osmocom.org/c/libosmocore/+/39276/comment/4b93886b_2c0a0c75?… :
PS1, Line 22:
Fixes: df1ee8568b97dbf6d5268a83d1715a1c1fffb2de
File src/core/osmo_io.c:
https://gerrit.osmocom.org/c/libosmocore/+/39276/comment/e18c5373_bd05e625?… :
PS1, Line 760: return iofd->fd == fd ? 0 : -ENOTSUP;
since you are not setting iofd->fd in the code path you removed, this check is also wrong now?
https://gerrit.osmocom.org/c/libosmocore/+/39276/comment/0ca71e1b_45f322fe?… :
PS1, Line 761: } else {
if clause is an early return, this "else" can be removed and the assignment done directly.
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If8b8486ad7934afa203dfe1e996c9217373a017b
Gerrit-Change-Number: 39276
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: falconia <falcon(a)freecalypso.org>
Gerrit-Comment-Date: Thu, 09 Jan 2025 19:48:45 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email )
Change subject: osmo_iofd_register: fix the case of changing fd
......................................................................
osmo_iofd_register: fix the case of changing fd
Doxygen description for this function states:
\param[in] fd the system fd number that will be registered.
If you did not yet specify the file descriptor number during
osmo_fd_setup(), or if it has changed since then, you can state
the [new] file descriptor number as argument.
If you wish to proceed with the previously specified file descriptor
number, pass -1.
However, the case where a new fd is passed to osmo_iofd_register()
while the structure contains an old (but unregistered) fd was not
handled correctly: the code would proceed with re-registering the old
fd, ignoring the newly passed one.
Change-Id: If8b8486ad7934afa203dfe1e996c9217373a017b
---
M src/core/osmo_io.c
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/76/39276/1
diff --git a/src/core/osmo_io.c b/src/core/osmo_io.c
index e109cdf..1e3e114 100644
--- a/src/core/osmo_io.c
+++ b/src/core/osmo_io.c
@@ -753,13 +753,13 @@
}
if (fd < 0)
fd = iofd->fd;
- else if (iofd->fd < 0)
- iofd->fd = fd;
if (IOFD_FLAG_ISSET(iofd, IOFD_FLAG_FD_REGISTERED)) {
/* If re-registering same fd, handle as NO-OP.
* New FD should go through unregister() first. */
return iofd->fd == fd ? 0 : -ENOTSUP;
+ } else {
+ iofd->fd = fd;
}
rc = osmo_iofd_ops.register_fd(iofd);
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39276?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If8b8486ad7934afa203dfe1e996c9217373a017b
Gerrit-Change-Number: 39276
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/python/pyosmocom/+/39162?usp=email )
Change subject: construct: add length steps to StripTrailerAdapter
......................................................................
construct: add length steps to StripTrailerAdapter
The class StripTrailerAdapter allows to remove trailing bytes that
match a specified value from the encoding result of a sub-construct.
The result is always the shortest possible remainder of bytes that
do not match the secified value.
Unfortunately there are specifications that explicitly require the
length of the result to fit into a limited set of possible length
values. For example: A result may be either one byte or three byte
long. To cover those cases as well, let's add an array parameter
where we can configure the allowed length values of the encoding
result.
Related: OS#6679
Change-Id: I86df064fa41db85923eeb0d83cc399504fdd4488
---
M src/osmocom/construct.py
M tests/test_construct.py
2 files changed, 41 insertions(+), 3 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/src/osmocom/construct.py b/src/osmocom/construct.py
index c69b44f..d4284d9 100644
--- a/src/osmocom/construct.py
+++ b/src/osmocom/construct.py
@@ -413,16 +413,20 @@
Encoder removes all trailing bytes matching the default_value
Decoder pads input data up to total_length with default_value
+ In case the encoding restricts the length of the result to specific values, the API user may set those restrictions
+ using the steps parameter. (e.g. encoded result must be either 1 or 3 byte long, steps would be set to [1,3])
+
This is used in constellations like "FlagsEnum(StripTrailerAdapter(GreedyBytes, 3), ..."
where you have a bit-mask that may have 1, 2 or 3 bytes, depending on whether or not any
of the LSBs are actually set.
"""
- def __init__(self, subcon, total_length:int, default_value=b'\x00', min_len=1):
+ def __init__(self, subcon, total_length:int, default_value=b'\x00', min_len=1, steps:typing.List[int]=[]):
super().__init__(subcon)
assert len(default_value) == 1
self.total_length = total_length
self.default_value = default_value
self.min_len = min_len
+ self.steps = steps
def _decode(self, obj, context, path):
assert isinstance(obj, bytes)
@@ -435,9 +439,17 @@
assert isinstance(obj, int)
obj = obj.to_bytes(self.total_length, 'big')
# remove trailing bytes if they are zero
+
+ obj_step_aligned = obj
while len(obj) > self.min_len and obj[-1] == self.default_value[0]:
obj = obj[:-1]
- return obj
+ if len(obj) in self.steps:
+ obj_step_aligned = obj
+
+ if self.steps == []:
+ return obj
+ else:
+ return obj_step_aligned;
def filter_dict(d, exclude_prefix='_'):
diff --git a/tests/test_construct.py b/tests/test_construct.py
index bcb2cf8..e4234db 100755
--- a/tests/test_construct.py
+++ b/tests/test_construct.py
@@ -90,13 +90,39 @@
final_application=0x0200, global_service=0x0100,
receipt_generation=0x80, ciphered_load_file_data_block=0x40,
contactless_activation=0x20, contactless_self_activation=0x10)
+ PrivilegesSteps = FlagsEnum(StripTrailerAdapter(GreedyBytes, 3, steps = [1,3]), security_domain=0x800000,
+ dap_verification=0x400000,
+ delegated_management=0x200000, card_lock=0x100000,
+ card_terminate=0x080000, card_reset=0x040000,
+ cvm_management=0x020000, mandated_dap_verification=0x010000,
+ trusted_path=0x8000, authorized_management=0x4000,
+ token_management=0x2000, global_delete=0x1000,
+ global_lock=0x0800, global_registry=0x0400,
+ final_application=0x0200, global_service=0x0100,
+ receipt_generation=0x80, ciphered_load_file_data_block=0x40,
+ contactless_activation=0x20, contactless_self_activation=0x10)
examples = ['00', '80', '8040', '400010']
- def test_examples(self):
+ def test_encdec(self):
for e in self.examples:
dec = self.Privileges.parse(h2b(e))
reenc = self.Privileges.build(dec)
self.assertEqual(e, b2h(reenc))
+ def test_enc(self):
+ enc = self.Privileges.build({'dap_verification' : True})
+ self.assertEqual(b2h(enc), '40')
+ enc = self.Privileges.build({'dap_verification' : True, 'global_service' : True})
+ self.assertEqual(b2h(enc), '4001')
+ enc = self.Privileges.build({'dap_verification' : True, 'global_service' : True, 'contactless_self_activation' : True})
+ self.assertEqual(b2h(enc), '400110')
+
+ enc = self.PrivilegesSteps.build({'dap_verification' : True})
+ self.assertEqual(b2h(enc), '40')
+ enc = self.PrivilegesSteps.build({'dap_verification' : True, 'global_service' : True})
+ self.assertEqual(b2h(enc), '400100')
+ enc = self.PrivilegesSteps.build({'dap_verification' : True, 'global_service' : True, 'contactless_self_activation' : True})
+ self.assertEqual(b2h(enc), '400110')
+
class TestAdapters(unittest.TestCase):
def test_dns_adapter(self):
--
To view, visit https://gerrit.osmocom.org/c/python/pyosmocom/+/39162?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: I86df064fa41db85923eeb0d83cc399504fdd4488
Gerrit-Change-Number: 39162
Gerrit-PatchSet: 2
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>