File U_17-Use-safe_unpack32.patch of Package slurm.32313
From: Tim Wickberg <tim@schedmd.com>
Date: Wed Nov 29 15:26:20 2023 -0700
Subject: [PATCH 17/28]Use safe_unpack32().
Patch-mainline: Upstream
Git-repo: https://github.com/SchedMD/slurm
Git-commit: afc41842de210729b2baf272935fab0f6b35aeea
References: bsc#1218046, bsc#1218050, bsc#1218051, bsc#1218053
Signed-off-by: Egbert Eich <eich@suse.de>
Signed-off-by: Egbert Eich <eich@suse.com>
---
src/common/pack.c | 49 +++++++++++++++++--------------------------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/src/common/pack.c b/src/common/pack.c
index 8da83e4018..2fa3285cb9 100644
--- a/src/common/pack.c
+++ b/src/common/pack.c
@@ -861,14 +861,7 @@ extern void packmem(void *valp, uint32_t size_val, buf_t *buffer)
*/
int unpackmem_ptr(char **valp, uint32_t * size_valp, Buf buffer)
{
- uint32_t ns;
-
- if (remaining_buf(buffer) < sizeof(ns))
- return SLURM_ERROR;
-
- memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
- *size_valp = ntohl(ns);
- buffer->processed += sizeof(ns);
+ safe_unpack32(size_valp, buffer);
if (*size_valp > MAX_ARRAY_LEN_LARGE) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
@@ -883,6 +876,9 @@ int unpackmem_ptr(char **valp, uint32_t * size_valp, Buf buffer)
} else
*valp = NULL;
return SLURM_SUCCESS;
+
+unpack_error:
+ return SLURM_ERROR;
}
/*
@@ -896,14 +892,7 @@ int unpackmem_ptr(char **valp, uint32_t * size_valp, Buf buffer)
*/
int unpackmem_xmalloc(char **valp, uint32_t * size_valp, Buf buffer)
{
- uint32_t ns;
-
- if (remaining_buf(buffer) < sizeof(ns))
- return SLURM_ERROR;
-
- memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
- *size_valp = ntohl(ns);
- buffer->processed += sizeof(ns);
+ safe_unpack32(size_valp, buffer);
if (*size_valp > MAX_ARRAY_LEN_LARGE) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
@@ -920,6 +909,9 @@ int unpackmem_xmalloc(char **valp, uint32_t * size_valp, Buf buffer)
} else
*valp = NULL;
return SLURM_SUCCESS;
+
+unpack_error:
+ return SLURM_ERROR;
}
/*
@@ -933,15 +925,9 @@ int unpackmem_xmalloc(char **valp, uint32_t * size_valp, Buf buffer)
*/
int unpackmem_malloc(char **valp, uint32_t * size_valp, Buf buffer)
{
- uint32_t ns;
-
- if (remaining_buf(buffer) < sizeof(ns))
- return SLURM_ERROR;
+ safe_unpack32(size_valp, buffer);
- memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
- *size_valp = ntohl(ns);
- buffer->processed += sizeof(ns);
- if (*size_valp > MAX_ARRAY_LEN_SMALL) {
+ if (*size_valp > MAX_PACK_MEM_LEN) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
__func__, *size_valp, MAX_ARRAY_LEN_SMALL);
return SLURM_ERROR;
@@ -960,6 +946,9 @@ int unpackmem_malloc(char **valp, uint32_t * size_valp, Buf buffer)
} else
*valp = NULL;
return SLURM_SUCCESS;
+
+unpack_error:
+ return SLURM_ERROR;
}
/*
@@ -978,14 +967,7 @@ int unpackmem_malloc(char **valp, uint32_t * size_valp, Buf buffer)
*/
int unpackstr_xmalloc_escaped(char **valp, uint32_t *size_valp, Buf buffer)
{
- uint32_t ns;
-
- if (remaining_buf(buffer) < sizeof(ns))
- return SLURM_ERROR;
-
- memcpy(&ns, &buffer->head[buffer->processed], sizeof(ns));
- *size_valp = ntohl(ns);
- buffer->processed += sizeof(ns);
+ safe_unpack32(size_valp, buffer);
if (*size_valp > MAX_PACK_MEM_LEN) {
error("%s: Buffer to be unpacked is too large (%u > %u)",
@@ -1024,6 +1006,9 @@ int unpackstr_xmalloc_escaped(char **valp, uint32_t *size_valp, Buf buffer)
} else
*valp = NULL;
return SLURM_SUCCESS;
+
+unpack_error:
+ return SLURM_ERROR;
}
int unpackstr_xmalloc_chooser(char **valp, uint32_t *size_valp, Buf buf)