From 721e60668ce4e496532594cd64f5456f9bf4acfa Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Thu, 15 Apr 2010 21:56:06 +0000 Subject: [PATCH] no change in functionality, but cleaner/smaller logic by adding subroutine --- src/slurmctld/job_mgr.c | 137 ++++++++++++-------------------------- src/slurmctld/slurmctld.h | 4 -- src/slurmctld/step_mgr.c | 29 +++++--- 3 files changed, 61 insertions(+), 109 deletions(-) diff --git a/src/slurmctld/job_mgr.c b/src/slurmctld/job_mgr.c index dc2f299b933..55230f24afe 100644 --- a/src/slurmctld/job_mgr.c +++ b/src/slurmctld/job_mgr.c @@ -3114,107 +3114,54 @@ cleanup_fail: return error_code; } +static int _test_strlen(char *test_str, char *str_name, int max_str_len) +{ + int i = 0; + + if (test_str) + i = strlen(test_str); + if (i > max_str_len) { + info("job_create_request: strlen(%s) too big (%d > %d)", + str_name, i, max_str_len); + return ESLURM_PATHNAME_TOO_LONG; + } + return SLURM_SUCCESS; +} + /* Perform some size checks on strings we store to prevent * malicious user filling slurmctld's memory * RET 0 or error code */ static int _validate_job_create_req(job_desc_msg_t * job_desc) { - if (job_desc->account && (strlen(job_desc->account) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(account) too big (%d)", - strlen(job_desc->account)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->alloc_node && - (strlen(job_desc->alloc_node) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(alloc_node) too big (%d)", - strlen(job_desc->alloc_node)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->blrtsimage && - (strlen(job_desc->blrtsimage) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(blrtsimage) too big (%d)", - strlen(job_desc->blrtsimage)); + if (_test_strlen(job_desc->account, "account", 1024) || + _test_strlen(job_desc->alloc_node, "alloc_node", 1024) || + _test_strlen(job_desc->blrtsimage, "blrtsimage", 1024) || + _test_strlen(job_desc->ckpt_dir, "ckpt_dir", 1024) || + _test_strlen(job_desc->comment, "comment", 1024) || + _test_strlen(job_desc->cpu_bind, "cpu_bind", 1024) || + _test_strlen(job_desc->dependency, "dependency", 1024) || + _test_strlen(job_desc->exc_nodes, "exc_nodes", 1024) || + _test_strlen(job_desc->features, "features", 1024) || + _test_strlen(job_desc->licenses, "licenses", 1024) || + _test_strlen(job_desc->linuximage, "linuximage", 1024) || + _test_strlen(job_desc->mail_user, "mail_user", 1024) || + _test_strlen(job_desc->mem_bind, "mem_bind", 1024) || + _test_strlen(job_desc->mloaderimage, "mloaderimage", 1024) || + _test_strlen(job_desc->name, "name", 1024) || + _test_strlen(job_desc->network, "network", 1024) || + _test_strlen(job_desc->partition, "partition", 1024) || + _test_strlen(job_desc->qos, "qos", 1024) || + _test_strlen(job_desc->ramdiskimage, "ramdiskimage", 1024) || + _test_strlen(job_desc->req_nodes, "req_nodes", 1024) || + _test_strlen(job_desc->reservation, "reservation", 1024) || + _test_strlen(job_desc->script, "script", 1024*128) || + _test_strlen(job_desc->std_err, "std_err", 1024) || + _test_strlen(job_desc->std_in, "std_in", 1024) || + _test_strlen(job_desc->std_out, "std_out", 1024) || + _test_strlen(job_desc->wckey, "wckey", 1024) || + _test_strlen(job_desc->work_dir, "work_dir", 1024)) return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->comment && (strlen(job_desc->comment) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(comment) too big (%d)", - strlen(job_desc->comment)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->dependency && - (strlen(job_desc->dependency) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(dependency) too big (%d)", - strlen(job_desc->dependency)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->std_err && (strlen(job_desc->std_err) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(err) too big (%d)", - strlen(job_desc->std_err)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->features && (strlen(job_desc->features) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(features) too big (%d)", - strlen(job_desc->features)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->std_in && (strlen(job_desc->std_in) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(in) too big (%d)", - strlen(job_desc->std_in)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->linuximage && - (strlen(job_desc->linuximage) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(linuximage) too big (%d)", - strlen(job_desc->linuximage)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->licenses && (strlen(job_desc->licenses) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(licenses) too big (%d)", - strlen(job_desc->licenses)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->mail_user && (strlen(job_desc->mail_user) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(mail_user) too big (%d)", - strlen(job_desc->mail_user)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->mloaderimage && - (strlen(job_desc->mloaderimage) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(mloaderimage) too big (%d)", - strlen(job_desc->mloaderimage)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->name && (strlen(job_desc->name) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(name) too big (%d)", - strlen(job_desc->name)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->network && (strlen(job_desc->network) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(network) too big (%d)", - strlen(job_desc->network)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->std_out && (strlen(job_desc->std_out) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(out) too big (%d)", - strlen(job_desc->std_out)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->partition && (strlen(job_desc->partition) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(partition) too big (%d)", - strlen(job_desc->partition)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->ramdiskimage && - (strlen(job_desc->ramdiskimage) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(ramdiskimage) too big (%d)", - strlen(job_desc->ramdiskimage)); - return ESLURM_PATHNAME_TOO_LONG; - } - if (job_desc->work_dir && (strlen(job_desc->work_dir) > MAX_STR_LEN)) { - info("_validate_job_create_req: strlen(work_dir) too big (%d)", - strlen(job_desc->work_dir)); - return ESLURM_PATHNAME_TOO_LONG; - } + if (!valid_spank_job_env(job_desc->spank_job_env, job_desc->spank_job_env_size, job_desc->user_id)) { diff --git a/src/slurmctld/slurmctld.h b/src/slurmctld/slurmctld.h index 2402686a6cd..f650653326e 100644 --- a/src/slurmctld/slurmctld.h +++ b/src/slurmctld/slurmctld.h @@ -87,10 +87,6 @@ /* Maximum parallel threads to service incoming RPCs */ #define MAX_SERVER_THREADS 100 -/* Maximum size we want to support for user strings (e.g. job comment). - * Try to prevent user from filling slurmctld's memory */ -#define MAX_STR_LEN 64 * 1024 - /* Perform full slurmctld's state every PERIODIC_CHECKPOINT seconds */ #define PERIODIC_CHECKPOINT 300 diff --git a/src/slurmctld/step_mgr.c b/src/slurmctld/step_mgr.c index 93c382aa1cd..d63dddde451 100644 --- a/src/slurmctld/step_mgr.c +++ b/src/slurmctld/step_mgr.c @@ -1261,6 +1261,20 @@ static void _step_dealloc_lps(struct step_record *step_ptr) #endif } +static int _test_strlen(char *test_str, char *str_name, int max_str_len) +{ + int i = 0; + + if (test_str) + i = strlen(test_str); + if (i > max_str_len) { + info("step_create_request: strlen(%s) too big (%d > %d)", + str_name, i, max_str_len); + return ESLURM_PATHNAME_TOO_LONG; + } + return SLURM_SUCCESS; +} + /* * step_create - creates a step_record in step_specs->job_id, sets up the * according to the step_specs. @@ -1333,16 +1347,11 @@ step_create(job_step_create_request_msg_t *step_specs, return ESLURM_TASKDIST_ARBITRARY_UNSUPPORTED; } - if ((step_specs->host && - (strlen(step_specs->host) > MAX_STR_LEN)) || - (step_specs->node_list && - (strlen(step_specs->node_list) > MAX_STR_LEN)) || - (step_specs->network && - (strlen(step_specs->network) > MAX_STR_LEN)) || - (step_specs->name && - (strlen(step_specs->name) > MAX_STR_LEN)) || - (step_specs->ckpt_dir && - (strlen(step_specs->ckpt_dir) > MAX_STR_LEN))) + if (_test_strlen(step_specs->ckpt_dir, "ckpt_dir", 1024) || + _test_strlen(step_specs->host, "host", 1024) || + _test_strlen(step_specs->name, "name", 1024) || + _test_strlen(step_specs->network, "network", 1024) || + _test_strlen(step_specs->node_list, "node_list", 1024)) return ESLURM_PATHNAME_TOO_LONG; /* if the overcommit flag is checked, we 0 set cpu_count=0 -- GitLab