Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2aeb945

Browse files
committed
Fixed possibly unsafe memcpy() in scheduler_manager.c
1) Changed memcpy() to strcpy() to make sure that we copy the string with '\0' in the end 2) Added a strlen check to make sure that we don't try to copy a string that is too long into a fixed-length array of chars
1 parent 3e1c82d commit 2aeb945

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/scheduler_manager.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,21 @@ int launch_executor_worker(scheduler_manager_ctx_t *ctx, scheduler_manager_slot_
946946
void init_executor_shared_data(schd_executor_share_t *data, scheduler_manager_ctx_t *ctx, job_t *job)
947947
{
948948
data->status = SchdExecutorInit;
949-
memcpy(data->database, ctx->database, strlen(ctx->database));
950-
memcpy(data->nodename, job->node, strlen(job->node));
949+
950+
if(strlen(ctx->database) < PGPRO_SCHEDULER_DBNAME_MAX)
951+
strcpy(data->database, ctx->database);
952+
else
953+
elog(ERROR, "String \"%s\"\n"
954+
"has %zu symbols, while it should have less than %d symbols.",
955+
ctx->database, strlen(ctx->database), PGPRO_SCHEDULER_DBNAME_MAX);
956+
957+
if(strlen(job->node) < PGPRO_SCHEDULER_NODENAME_MAX)
958+
strcpy(data->nodename, job->node);
959+
else
960+
elog(ERROR, "String \"%s\"\n"
961+
"has %zu symbols, while it should have less than %d symbols.",
962+
job->node, strlen(job->node), PGPRO_SCHEDULER_NODENAME_MAX);
963+
951964
data->new_job = true;
952965

953966
if(job)
@@ -1775,8 +1788,20 @@ int start_at_worker(scheduler_manager_ctx_t *ctx, int pos)
17751788
item->res_owner = CurrentResourceOwner;
17761789
shm_data = dsm_segment_address(item->shared);
17771790

1778-
memcpy(shm_data->database, ctx->database, strlen(ctx->database));
1779-
memcpy(shm_data->nodename, ctx->nodename, strlen(ctx->nodename));
1791+
if(strlen(ctx->database) < PGPRO_SCHEDULER_DBNAME_MAX)
1792+
strcpy(shm_data->database, ctx->database);
1793+
else
1794+
elog(ERROR, "String \"%s\"\n"
1795+
"has %zu symbols, while it should have less than %d symbols.",
1796+
ctx->database, strlen(ctx->database), PGPRO_SCHEDULER_DBNAME_MAX);
1797+
1798+
if(strlen(ctx->nodename) < PGPRO_SCHEDULER_NODENAME_MAX)
1799+
strcpy(shm_data->nodename, ctx->nodename);
1800+
else
1801+
elog(ERROR, "String \"%s\"\n"
1802+
"has %zu symbols, while it should have less than %d symbols.",
1803+
ctx->nodename, strlen(ctx->nodename), PGPRO_SCHEDULER_NODENAME_MAX);
1804+
17801805
shm_data->stop_worker = false;
17811806
shm_data->status = SchdExecutorInit;
17821807
shm_data->start_at = 0;

0 commit comments

Comments
 (0)