staging: vc04_services: use snprintf instead of sprintf
authorRicardo B. Marliere <ricardo@marliere.net>
Wed, 25 Oct 2023 12:26:34 +0000 (09:26 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Oct 2023 11:09:42 +0000 (13:09 +0200)
All the occurrences of sprintf usage under vc04_services can be safely
replaced by snprintf, so as to avoid any possible overflow.

Suggested-by: Dan Carpenter <dan.carpenter@linaro.org>
Suggested-by: Umang Jain <umang.jain@ideasonboard.com>
Signed-off-by: "Ricardo B. Marliere" <ricardo@marliere.net>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Link: https://lore.kernel.org/r/20231025122632.307385-4-ricardo@marliere.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

index e860fb89d42e7349ae997483154af99ba1d5cc01..e6e89784d84b93b28d5b285562db30ecbdb6647c 100644 (file)
@@ -855,7 +855,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
                return -EINVAL;
 
        inp->type = V4L2_INPUT_TYPE_CAMERA;
-       sprintf((char *)inp->name, "Camera %u", inp->index);
+       snprintf((char *)inp->name, sizeof(inp->name), "Camera %u", inp->index);
        return 0;
 }
 
index de6a24304a4d98243a4589da1341145b88109f8a..9fb8f657cc781ad41454dc67ef2608d6505db9f7 100644 (file)
@@ -1451,12 +1451,12 @@ vchiq_use_internal(struct vchiq_state *state, struct vchiq_service *service,
        }
 
        if (use_type == USE_TYPE_VCHIQ) {
-               sprintf(entity, "VCHIQ:   ");
+               snprintf(entity, sizeof(entity), "VCHIQ:   ");
                entity_uc = &arm_state->peer_use_count;
        } else if (service) {
-               sprintf(entity, "%p4cc:%03d",
-                       &service->base.fourcc,
-                       service->client_id);
+               snprintf(entity, sizeof(entity), "%p4cc:%03d",
+                        &service->base.fourcc,
+                        service->client_id);
                entity_uc = &service->service_use_count;
        } else {
                vchiq_log_error(state->dev, VCHIQ_SUSPEND, "%s null service ptr", __func__);
@@ -1506,12 +1506,12 @@ vchiq_release_internal(struct vchiq_state *state, struct vchiq_service *service)
        }
 
        if (service) {
-               sprintf(entity, "%p4cc:%03d",
-                       &service->base.fourcc,
-                       service->client_id);
+               snprintf(entity, sizeof(entity), "%p4cc:%03d",
+                        &service->base.fourcc,
+                        service->client_id);
                entity_uc = &service->service_use_count;
        } else {
-               sprintf(entity, "PEER:   ");
+               snprintf(entity, sizeof(entity), "PEER:   ");
                entity_uc = &arm_state->peer_use_count;
        }