From e02b54ec57b1bb63d3ba996dc29637e80abe4865 Mon Sep 17 00:00:00 2001 From: Egor Shestakov Date: Wed, 12 Mar 2025 12:16:04 +0000 Subject: [PATCH] add buffer size check in find_calibration Drop find_calibration_by_model function that was occassionally, as I suppose, marked not static. --- src/dcp.c | 19 ++++++------------- src/dcp.h | 2 +- src/process_pipeline.c | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/dcp.c b/src/dcp.c index ea545de..834e4d8 100644 --- a/src/dcp.c +++ b/src/dcp.c @@ -12,8 +12,12 @@ #endif bool -find_calibration_by_model(char *conffile, char *model, const char *sensor) +find_calibration(size_t size, char *conffile, const char *sensor) { + char model[512]; + int model_found = libmegapixels_get_model(sizeof(model), model); + if(!model_found) + return false; static const char *paths[] = { "config/%s,%s.dcp", SYSCONFDIR "/megapixels/config/%s,%s.dcp", @@ -21,27 +25,16 @@ find_calibration_by_model(char *conffile, char *model, const char *sensor) NULL }; for (const char *fmt = paths[0]; fmt; fmt++) { - sprintf(conffile, fmt, model, sensor); + snprintf(conffile, size, fmt, model, sensor); if (access(conffile, F_OK) != -1) { printf("Found calibration file at %s\n", conffile); return true; } } - printf("No calibration found for %s,%s\n", model, sensor); return false; } -bool -find_calibration(char *conffile, const char *sensor) -{ - char model[512]; - int model_found = libmegapixels_get_model(sizeof(model), model); - if (!model_found) - return false; - return find_calibration_by_model(conffile, model, sensor); -} - struct MPCameraCalibration parse_calibration_file(const char *path) { diff --git a/src/dcp.h b/src/dcp.h index 4c0d87d..5f4b0f5 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -19,4 +19,4 @@ struct MPCameraCalibration { struct MPCameraCalibration parse_calibration_file(const char *path); -bool find_calibration(char *conffile, const char *sensor); +bool find_calibration(size_t size, char *conffile, const char *sensor); diff --git a/src/process_pipeline.c b/src/process_pipeline.c index d4dadb8..c26e832 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -1567,7 +1567,7 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state) if (camera_changed) { char cf[PATH_MAX]; - if (find_calibration(cf, state_proc.camera->name)) { + if (find_calibration(sizeof(cf), cf, state_proc.camera->name)) { state_proc.calibration = parse_calibration_file(cf); } else { fprintf(stderr, "No calibration for %s\n", state_proc.camera->name);