fix: check input boundary
This commit is contained in:
parent
69d3f8cc0f
commit
969fa07d28
|
@ -224,6 +224,9 @@ int jobs_show(FILE *file) {
|
||||||
* value returned is the job ID assigned to the pipeline.
|
* value returned is the job ID assigned to the pipeline.
|
||||||
*/
|
*/
|
||||||
int jobs_run(PIPELINE *pline) {
|
int jobs_run(PIPELINE *pline) {
|
||||||
|
if (!pline)
|
||||||
|
return -1;
|
||||||
|
|
||||||
pline = copy_pipeline(pline);
|
pline = copy_pipeline(pline);
|
||||||
// return -1 if no place for new job
|
// return -1 if no place for new job
|
||||||
if (job_current_size + 1 >= MAX_JOBS)
|
if (job_current_size + 1 >= MAX_JOBS)
|
||||||
|
@ -423,6 +426,8 @@ char **jobs_get_args(ARG *args) {
|
||||||
* or -1 if any error occurs that makes it impossible to wait for the specified job.
|
* or -1 if any error occurs that makes it impossible to wait for the specified job.
|
||||||
*/
|
*/
|
||||||
int jobs_wait(int jobid) {
|
int jobs_wait(int jobid) {
|
||||||
|
if (jobid >= MAX_JOBS || jobid < 0)
|
||||||
|
return -1;
|
||||||
if (!job_data_array[jobid])
|
if (!job_data_array[jobid])
|
||||||
return -1;
|
return -1;
|
||||||
if (job_data_array[jobid]->status == COMPLETED ||
|
if (job_data_array[jobid]->status == COMPLETED ||
|
||||||
|
@ -458,6 +463,8 @@ int jobs_wait(int jobid) {
|
||||||
* has terminated, or -1 if the job has not yet terminated or if any other error occurs.
|
* has terminated, or -1 if the job has not yet terminated or if any other error occurs.
|
||||||
*/
|
*/
|
||||||
int jobs_poll(int jobid) {
|
int jobs_poll(int jobid) {
|
||||||
|
if (jobid >= MAX_JOBS || jobid < 0)
|
||||||
|
return -1;
|
||||||
if (!job_data_array[jobid])
|
if (!job_data_array[jobid])
|
||||||
return -1;
|
return -1;
|
||||||
if (job_data_array[jobid]->status != COMPLETED &&
|
if (job_data_array[jobid]->status != COMPLETED &&
|
||||||
|
@ -481,6 +488,8 @@ int jobs_poll(int jobid) {
|
||||||
* @return 0 if the job was successfully expunged, -1 if the job could not be expunged.
|
* @return 0 if the job was successfully expunged, -1 if the job could not be expunged.
|
||||||
*/
|
*/
|
||||||
int jobs_expunge(int jobid) {
|
int jobs_expunge(int jobid) {
|
||||||
|
if (jobid >= MAX_JOBS || jobid < 0)
|
||||||
|
return -1;
|
||||||
if (!job_data_array[jobid])
|
if (!job_data_array[jobid])
|
||||||
return -1;
|
return -1;
|
||||||
if (job_data_array[jobid]->status != COMPLETED &&
|
if (job_data_array[jobid]->status != COMPLETED &&
|
||||||
|
@ -523,6 +532,8 @@ int jobs_expunge(int jobid) {
|
||||||
* error occurred.
|
* error occurred.
|
||||||
*/
|
*/
|
||||||
int jobs_cancel(int jobid) {
|
int jobs_cancel(int jobid) {
|
||||||
|
if (jobid >= MAX_JOBS || jobid < 0)
|
||||||
|
return -1;
|
||||||
if (!job_data_array[jobid])
|
if (!job_data_array[jobid])
|
||||||
return -1;
|
return -1;
|
||||||
if (job_data_array[jobid]->status == COMPLETED ||
|
if (job_data_array[jobid]->status == COMPLETED ||
|
||||||
|
@ -554,6 +565,8 @@ int jobs_cancel(int jobid) {
|
||||||
* output available, otherwise NULL.
|
* output available, otherwise NULL.
|
||||||
*/
|
*/
|
||||||
char *jobs_get_output(int jobid) {
|
char *jobs_get_output(int jobid) {
|
||||||
|
if (jobid >= MAX_JOBS || jobid < 0)
|
||||||
|
return NULL;
|
||||||
if (!job_data_array[jobid])
|
if (!job_data_array[jobid])
|
||||||
return NULL;
|
return NULL;
|
||||||
if (job_data_array[jobid]->status != COMPLETED &&
|
if (job_data_array[jobid]->status != COMPLETED &&
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
* otherwise NULL.
|
* otherwise NULL.
|
||||||
*/
|
*/
|
||||||
char *store_get_string(char *var) {
|
char *store_get_string(char *var) {
|
||||||
|
if (!var)
|
||||||
|
return -1;
|
||||||
store_data *data = store_get_data(var);
|
store_data *data = store_get_data(var);
|
||||||
if (data)
|
if (data)
|
||||||
return data->value;
|
return data->value;
|
||||||
|
@ -50,6 +52,8 @@ char *store_get_string(char *var) {
|
||||||
* otherwise 0 is returned.
|
* otherwise 0 is returned.
|
||||||
*/
|
*/
|
||||||
int store_get_int(char *var, long *valp) {
|
int store_get_int(char *var, long *valp) {
|
||||||
|
if (!var || !valp)
|
||||||
|
return -1;
|
||||||
store_data *data = store_get_data(var);
|
store_data *data = store_get_data(var);
|
||||||
if (data) {
|
if (data) {
|
||||||
// is NULL
|
// is NULL
|
||||||
|
@ -91,6 +95,9 @@ int store_get_int(char *var, long *valp) {
|
||||||
* un-set.
|
* un-set.
|
||||||
*/
|
*/
|
||||||
int store_set_string(char *var, char *val) {
|
int store_set_string(char *var, char *val) {
|
||||||
|
if (!var)
|
||||||
|
return -1;
|
||||||
|
|
||||||
store_data* data = store_get_data(var);
|
store_data* data = store_get_data(var);
|
||||||
// if want to unset a value that does not exist
|
// if want to unset a value that does not exist
|
||||||
if (!data && !val)
|
if (!data && !val)
|
||||||
|
@ -133,6 +140,8 @@ int store_set_string(char *var, char *val) {
|
||||||
* @param val The value to set.
|
* @param val The value to set.
|
||||||
*/
|
*/
|
||||||
int store_set_int(char *var, long val) {
|
int store_set_int(char *var, long val) {
|
||||||
|
if (!var)
|
||||||
|
return -1;
|
||||||
// if val is 0, set var to 0
|
// if val is 0, set var to 0
|
||||||
if (val == 0)
|
if (val == 0)
|
||||||
return store_set_string(var, "0");
|
return store_set_string(var, "0");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user