diff --git a/camlibs/canon/library.c b/camlibs/canon/library.c index dc89b49963..02fe91e7b7 100644 --- a/camlibs/canon/library.c +++ b/camlibs/canon/library.c @@ -2419,19 +2419,15 @@ make_dir_func (CameraFilesystem __unused__ *fs, const char *folder, if (strlen (folder) > 1) { /* folder is something more than / */ - if (strlen (folder) + 1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "%s/%s", folder, name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "%s/%s", folder, name); } else { - if (1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "/%s", name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "/%s", name); } canonpath = gphoto2canonpath (camera, gppath, context); @@ -2461,19 +2457,15 @@ remove_dir_func (CameraFilesystem __unused__ *fs, const char *folder, if (strlen (folder) > 1) { /* folder is something more than / */ - if (strlen (folder) + 1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "%s/%s", folder, name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "%s/%s", folder, name); } else { - if (1 + strlen (name) > sizeof (gppath) - 1) { - GP_DEBUG ("make_dir_func: Arguments too long"); + if (snprintf (gppath, sizeof(gppath), "/%s", name) >= (int)sizeof(gppath)) { + GP_LOG_E ("Arguments too long"); return GP_ERROR_BAD_PARAMETERS; } - - snprintf (gppath, sizeof(gppath), "/%s", name); } canonpath = gphoto2canonpath (camera, gppath, context); diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index c21779a4d8..519fce52bf 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -5653,7 +5653,8 @@ camera_sigma_fp_capture (Camera *camera, CameraCaptureType type, CameraFilePath C_PTP_REP (ptp_sigma_fp_clearimagedbsingle(params, captstatus.imageid)); - snprintf (path->name, sizeof(path->name), "%s%s", pictfileinfoex2.name, pictfileinfoex2.fileext); + if (snprintf (path->name, sizeof(path->name), "%s%s", pictfileinfoex2.name, pictfileinfoex2.fileext) >= (int)sizeof(path->name)) + GP_LOG_E("pictfileinfoex2.name and .fileext did not fit into path->name"); strcpy (path->folder,"/"); ret = gp_file_new (&file); diff --git a/camlibs/st2205/st2205.h b/camlibs/st2205/st2205.h index 1ef322536f..6ea4c11d2e 100644 --- a/camlibs/st2205/st2205.h +++ b/camlibs/st2205/st2205.h @@ -68,7 +68,8 @@ enum { all unique and don't change when files with the same name (after converting to ascii and truncating) are added / deleted. */ #define ST2205_SET_FILENAME(dest, name, idx) \ - snprintf(dest, sizeof(st2205_filename), "%04d-%s.png", (idx) + 1, name) + if (snprintf(dest, sizeof(st2205_filename), "%04d-%s.png", (idx) + 1, name) >= (int)sizeof(st2205_filename)) \ + GP_LOG_E ("extended st2205_filename did not fit into dest") struct st2205_coord { uint16_t x; diff --git a/libgphoto2_port/usbdiskdirect/linux.c b/libgphoto2_port/usbdiskdirect/linux.c index 1c37fdf51b..6428a51fae 100644 --- a/libgphoto2_port/usbdiskdirect/linux.c +++ b/libgphoto2_port/usbdiskdirect/linux.c @@ -146,7 +146,8 @@ gp_port_usbdiskdirect_resolve_symlink (const char *link) } else { *slash = 0; len = strlen (path); - snprintf (path + len, sizeof (path) - len, "/%s", buf); + if (snprintf (path + len, sizeof (path) - len, "/%s", buf) >= (int)sizeof (path) - len) + return NULL; } if (stat (path, &st)) diff --git a/libgphoto2_port/usbscsi/linux.c b/libgphoto2_port/usbscsi/linux.c index 7667127bba..344f055ca7 100644 --- a/libgphoto2_port/usbscsi/linux.c +++ b/libgphoto2_port/usbscsi/linux.c @@ -141,7 +141,8 @@ gp_port_usbscsi_resolve_symlink (const char *link) } else { *slash = 0; len = strlen (path); - snprintf (path + len, sizeof (path) - len, "/%s", buf); + if (snprintf (path + len, sizeof (path) - len, "/%s", buf) >= (int)sizeof (path) - len) + return NULL; } if (stat (path, &st))