-
Notifications
You must be signed in to change notification settings - Fork 60
Check for non-existing/invalid/empty devices/paths in dm plugin and utils #1165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for non-existing/invalid/empty devices/paths in dm plugin and utils #1165
Conversation
📝 WalkthroughWalkthroughAdds input validation to device-mapper functions, introduces a block-device validation helper, switches several locals to g_autofree, defines a _C_LOCALE macro, and refactors tests to validate the new error behavior and use LVM/loop-device fixtures. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
No point in trying to return something that isn't actually a block device, like for example directories in /dev.
Good to see the test is actually working. (Of course I definitely meant to test this, I wouldn't forget to add the |
f903d27 to
78eeac0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/utils/dev_utils.h (1)
20-29:⚠️ Potential issue | 🟠 MajorAdd
<locale.h>forlocale_tand rename_C_LOCALEto avoid reserved identifier.Line 29 introduces
locale_tin a public header without including<locale.h>. While compilation currently succeeds because consuming.cfiles include<locale.h>themselves, this violates header self-containment and can break code that includes this header in isolation. Additionally,_C_LOCALEuses a reserved identifier pattern (underscore followed by uppercase letter); per the C standard, such names are reserved for the implementation. Rename toBD_UTILS_C_LOCALEor move the macro to a private header if it need not be public.🔧 Proposed fix
`#include` <glib.h> +#include <locale.h> `#ifndef` BD_UTILS_DEV_UTILS `#define` BD_UTILS_DEV_UTILS GQuark bd_utils_dev_utils_error_quark (void); `#define` BD_UTILS_DEV_UTILS_ERROR bd_utils_dev_utils_error_quark () /* "C" locale to get the locale-agnostic error messages */ -#define _C_LOCALE (locale_t) 0 +#define BD_UTILS_C_LOCALE (locale_t) 0
🤖 Fix all issues with AI agents
In `@src/plugins/dm.c`:
- Around line 215-223: In bd_dm_node_from_name, validate map_name (check for
NULL or empty) before using it to build dev_mapper_path; either move the
existing guard block above the g_strdup_printf call or initialize
dev_mapper_path to NULL and assign it after the guard, ensuring dev_mapper_path
is only created with a non-NULL map_name to avoid passing NULL into
g_strdup_printf (refer to variables map_name and dev_mapper_path and function
bd_dm_node_from_name).
- Around line 178-187: In bd_dm_name_from_node validate dm_node (check for NULL
or empty string) before calling g_strdup_printf so you never pass a NULL to
g_strdup_printf; move the existing if (!dm_node || strlen(dm_node) == 0) check
to the top of the function and only then build sys_path with
g_strdup_printf("/sys/class/block/%s/dm/name", dm_node), keeping the rest of the
error handling (g_set_error) and return semantics unchanged.
In `@tests/utils_test.py`:
- Around line 409-438: In setUp, the RuntimeError rethrown after
create_lio_device loses the original exception context; modify the except block
in UtilsStorageTestCase.setUp to re-raise the new RuntimeError using exception
chaining (raise RuntimeError("Failed to setup loop device for testing: %s" % e)
from e) so the original traceback from create_lio_device is preserved.
Summary by CodeRabbit
Bug Fixes
Tests