add buffer size check in find_calibration
Drop find_calibration_by_model function that was occassionally, as I suppose, marked not static.
This commit is contained in:
19
src/dcp.c
19
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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user