common: extract param_string_array from xpay into common.
What changed, and why it matters
This commit simply moves an existing helper function that parses a JSON array of strings from one file (inside the xpay plugin) to a shared common library. No behavior changes, no bug fixes, and no security implications are visible.
No security action needed; this is a routine refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts param_string_array() from plugins/xpay/xpay.c and places it in common/json_param.c with a corresponding declaration in common/json_param.h. The implementation is identical: it validates that the JSON token is an array, allocates a tal array, and copies each element as a string. This is a pure code-refactoring commit with no functional or security-relevant modifications.
Changed components
common/json_param.ccommon/json_param.hplugins/xpay/xpay.cInspect captured patch +21 / −16
diff --git a/common/json_param.c b/common/json_param.c
index 1b529707..18bd284c 100644
--- a/common/json_param.c
+++ b/common/json_param.c
@@ -478,6 +478,22 @@ struct command_result *param_string_or_array(struct command *cmd, const char *na
return param_string(cmd, name, buffer, tok, &(*result)->str);
}
+struct command_result *param_string_array(struct command *cmd, const char *name,
+ const char *buffer, const jsmntok_t *tok,
+ const char ***arr)
+{
+ size_t i;
+ const jsmntok_t *s;
+
+ if (tok->type != JSMN_ARRAY)
+ return command_fail_badparam(cmd, name, buffer, tok,
+ "should be an array");
+ *arr = tal_arr(cmd, const char *, tok->size);
+ json_for_each_arr(i, s, tok)
+ (*arr)[i] = json_strdup(*arr, buffer, s);
+ return NULL;
+}
+
struct command_result *param_invstring(struct command *cmd, const char *name,
const char * buffer, const jsmntok_t *tok,
const char **str)
diff --git a/common/json_param.h b/common/json_param.h
index 7b25715a..3f211f2d 100644
--- a/common/json_param.h
+++ b/common/json_param.h
@@ -209,6 +209,11 @@ struct command_result *param_string_or_array(struct command *cmd, const char *na
const char * buffer, const jsmntok_t *tok,
struct str_or_arr **result);
+/* Array of strings */
+struct command_result *param_string_array(struct command *cmd, const char *name,
+ const char *buffer, const jsmntok_t *tok,
+ const char ***arr);
+
/* Extract an invoice string from a generic string, strip the `lightning:`
* prefix from it if needed. */
struct command_result *param_invstring(struct command *cmd, const char *name,
diff --git a/plugins/xpay/xpay.c b/plugins/xpay/xpay.c
index fab8ae45..42c42c83 100644
--- a/plugins/xpay/xpay.c
+++ b/plugins/xpay/xpay.c
@@ -2068,22 +2068,6 @@ static struct command_result *populate_private_layer(struct command *cmd,
return batch_done(aux_cmd, batch);
}
-static struct command_result *param_string_array(struct command *cmd, const char *name,
- const char *buffer, const jsmntok_t *tok,
- const char ***arr)
-{
- size_t i;
- const jsmntok_t *s;
-
- if (tok->type != JSMN_ARRAY)
- return command_fail_badparam(cmd, name, buffer, tok,
- "should be an array");
- *arr = tal_arr(cmd, const char *, tok->size);
- json_for_each_arr(i, s, tok)
- (*arr)[i] = json_strdup(*arr, buffer, s);
- return NULL;
-}
-
static struct command_result *
preapproveinvoice_succeed(struct command *cmd,
const char *method,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.