-
Notifications
You must be signed in to change notification settings - Fork 348
Sanitize characters in environment variables #3914
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -928,15 +928,20 @@ crmadmin_node(pcmk__output_t *out, va_list args) | |
{ | ||
const char *type = va_arg(args, const char *); | ||
const char *name = va_arg(args, const char *); | ||
const char *id = va_arg(args, const char *); | ||
const char *value = va_arg(args, const char *); | ||
bool bash_export = va_arg(args, int); | ||
|
||
if (bash_export) { | ||
return out->info(out, "export %s=%s", | ||
pcmk__s(name, "<null>"), pcmk__s(id, "")); | ||
int rc = pcmk_rc_ok; | ||
gchar *replaced = g_strcanon(g_strdup(pcmk__s(name, "<null>")), | ||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", '_'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. This is reasonable so that there's no disallowed character in an On the other hand, I don't think it's very useful in the first place. Even if the environment variable names match the node names, the user has to copy-paste the environment variable names into their future commands. So I guess this approach is fine, although I would be very okay with deprecating this functionality if you want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coverity thinks this is leaking memory. That's unfortunate: AFAICT it's totally safe and matches the GLib documentation's usage example. If you agree, then we can either add a suppression or free the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use
as the set of valid characters, so that it's clear we're not missing anything. (I know that you copy-pasted so it's fine in practice.) I have no strong feelings. Those GLib macros are intended for use with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We'd need to make sure no one is using it for anything - I guess asking on the users list, and maybe asking the pcs guys would be a good step. But yeah I'm happy with deprecating it too. This was introduced by 7e50ba6, which of course is not a very enlightening commit. |
||
|
||
rc = out->info(out, "export %s=%s", replaced, pcmk__s(value, "")); | ||
g_free(replaced); | ||
return rc; | ||
} else { | ||
return out->info(out, "%s node: %s (%s)", type ? type : "cluster", | ||
pcmk__s(name, "<null>"), pcmk__s(id, "<null>")); | ||
pcmk__s(name, "<null>"), pcmk__s(value, "<null>")); | ||
} | ||
} | ||
|
||
|
@@ -950,7 +955,7 @@ crmadmin_node_text(pcmk__output_t *out, va_list args) | |
} else { | ||
const char *type G_GNUC_UNUSED = va_arg(args, const char *); | ||
const char *name = va_arg(args, const char *); | ||
const char *id G_GNUC_UNUSED = va_arg(args, const char *); | ||
const char *value G_GNUC_UNUSED = va_arg(args, const char *); | ||
bool bash_export G_GNUC_UNUSED = va_arg(args, int); | ||
|
||
pcmk__formatted_printf(out, "%s\n", pcmk__s(name, "<null>")); | ||
|
@@ -965,13 +970,13 @@ crmadmin_node_xml(pcmk__output_t *out, va_list args) | |
{ | ||
const char *type = va_arg(args, const char *); | ||
const char *name = va_arg(args, const char *); | ||
const char *id = va_arg(args, const char *); | ||
const char *value = va_arg(args, const char *); | ||
bool bash_export G_GNUC_UNUSED = va_arg(args, int); | ||
|
||
pcmk__output_create_xml_node(out, PCMK_XE_NODE, | ||
PCMK_XA_TYPE, pcmk__s(type, "cluster"), | ||
PCMK_XA_NAME, pcmk__s(name, ""), | ||
PCMK_XA_ID, pcmk__s(id, ""), | ||
PCMK_XA_ID, pcmk__s(value, ""), | ||
NULL); | ||
return pcmk_rc_ok; | ||
} | ||
|
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.
I don't think this commit clarifies things. It's the "value" only in the context of the
"export <name>=<value>"
string. In all contexts, it's the node ID. In all other cases, the argument is either unused or treated just as a node ID:crmadmin_node_text()
: unusedcrmadmin_node_xml()
: used as ID