Merge branch 'nate-i50189-unix' into 'master'
See merge request SchedMD/dev/slurm!1691
diff --git a/src/common/http.c b/src/common/http.c
index fc4631d..73e03c8 100644
--- a/src/common/http.c
+++ b/src/common/http.c
@@ -202,12 +202,7 @@
buffer == '-' || buffer == '.' || buffer == '_');
}
-/*
- * decodes % sequence.
- * IN ptr pointing to % character
- * RET \0 on error or decoded character
- */
-static unsigned char _decode_seq(const char *ptr)
+extern unsigned char url_decode_escape_seq(const char *ptr)
{
if (isxdigit(*(ptr + 1)) && isxdigit(*(ptr + 2))) {
/* using uint16_t char to catch any overflows */
@@ -218,22 +213,24 @@
//TODO: find more invalid characters?
if (decoded == '\0') {
- error("%s: invalid URL escape sequence for 0x00",
- __func__);
+ log_flag(DATA, "%s: invalid URL escape sequence for 0x00",
+ __func__);
return '\0';
} else if (decoded >= 0xff) {
- error("%s: invalid URL escape sequence for 0x%02" PRIx16,
- __func__, decoded);
+ log_flag(DATA, "%s: invalid URL escape sequence for 0x%02" PRIx16,
+ __func__, decoded);
return '\0';
}
- debug5("%s: URL decoded: 0x%c%c -> %c (0x%02" PRIx16 ")",
+ log_flag(DATA, "%s: URL decoded: 0x%c%c -> %c (0x%02" PRIx16 ")",
__func__, (unsigned char) high, (unsigned char) low,
(unsigned char) decoded, decoded);
return (unsigned char) decoded;
} else {
- debug("%s: invalid URL escape sequence: %s", __func__, ptr);
+ log_flag_hex(DATA, ptr, strnlen(ptr, 3),
+ "%s: invalid URL escape sequence: %s", __func__,
+ ptr);
return '\0';
}
}
@@ -297,7 +294,7 @@
}
case '%': /* rfc3986 */
{
- const char c = _decode_seq(ptr);
+ const char c = url_decode_escape_seq(ptr);
if (c != '\0') {
/* shift past the hex value */
ptr += 2;
diff --git a/src/common/http.h b/src/common/http.h
index 7dee2b9..8705a2a 100644
--- a/src/common/http.h
+++ b/src/common/http.h
@@ -181,6 +181,13 @@
extern data_t *parse_url_path(const char *path, bool convert_types,
bool allow_templates);
+/*
+ * Decodes URL escape sequence (denoted via %XX)
+ * IN ptr - pointing to % character
+ * RET \0 on error or decoded character
+ */
+extern unsigned char url_decode_escape_seq(const char *ptr);
+
typedef struct {
url_scheme_t scheme;
char *host;
diff --git a/src/plugins/serializer/url-encoded/serializer_url_encoded.c b/src/plugins/serializer/url-encoded/serializer_url_encoded.c
index 189cc1c..b9ea5b6 100644
--- a/src/plugins/serializer/url-encoded/serializer_url_encoded.c
+++ b/src/plugins/serializer/url-encoded/serializer_url_encoded.c
@@ -39,6 +39,7 @@
#include "src/common/slurm_xlator.h"
#include "src/common/data.h"
+#include "src/common/http.h"
#include "src/common/log.h"
#include "src/common/read_config.h"
#include "src/common/slurm_protocol_api.h"
@@ -82,13 +83,6 @@
NULL
};
-static bool _is_char_hex(char buffer)
-{
- return (buffer >= '0' && buffer <= '9') ||
- (buffer >= 'a' && buffer <= 'f') ||
- (buffer >= 'A' && buffer <= 'F');
-}
-
extern int serialize_p_data_to_string(char **dest, size_t *length,
const data_t *src,
serializer_flags_t flags)
@@ -171,41 +165,6 @@
buffer == '-' || buffer == '.' || buffer == '_';
}
-/*
- * decodes % sequence.
- * IN ptr pointing to % character
- * RET \0 on error or decoded character
- */
-static unsigned char _decode_seq(const char *ptr)
-{
- if (_is_char_hex(*(ptr + 1)) && _is_char_hex(*(ptr + 2))) {
- /* using unsigned char to avoid any rollover */
- unsigned char high = *(ptr + 1);
- unsigned char low = *(ptr + 2);
- unsigned char decoded = (slurm_char_to_hex(high) << 4) +
- slurm_char_to_hex(low);
-
- //TODO: find more invalid characters?
- if (decoded == '\0') {
- error("%s: invalid URL escape sequence for 0x00",
- __func__);
- return '\0';
- } else if (decoded == 0xff) {
- error("%s: invalid URL escape sequence for 0xff",
- __func__);
- return '\0';
- }
-
- debug5("%s: URL decoded: 0x%c%c -> %c",
- __func__, high, low, decoded);
-
- return decoded;
- } else {
- debug("%s: invalid URL escape sequence: %s", __func__, ptr);
- return '\0';
- }
-}
-
extern int serialize_p_init(serializer_flags_t flags)
{
log_flag(DATA, "loaded");
@@ -246,7 +205,7 @@
switch (*ptr) {
case '%': /* rfc3986 */
{
- const char c = _decode_seq(ptr);
+ const char c = url_decode_escape_seq(ptr);
if (c != '\0') {
/* shift past the hex value */
ptr += 2;