Skip to content

Display and control your Android device

Report an error if the device name is truncated

Romain Vimont6ce3d289145b
diff --git a/app/src/v4l2_sink.c b/app/src/v4l2_sink.c
index f4e1ae40..8ba5414c 100644
--- a/app/src/v4l2_sink.c
+++ b/app/src/v4l2_sink.c
@@ -200,8 +200,12 @@ sc_v4l2_sink_open(struct sc_v4l2_sink *vs, const AVCodecContext *ctx,
goto error_avformat_free_context;
}
#else
- sc_strncpy(vs->format_ctx->filename, vs->device_name,
- sizeof(vs->format_ctx->filename));
+ size_t n = sc_strncpy(vs->format_ctx->filename, vs->device_name,
+ sizeof(vs->format_ctx->filename));
+ if (n == sizeof(vs->format_ctx->filename)) {
+ LOGE("Device name too long: %s", vs->device_name);
+ goto error_avformat_free_context;
+ }
#endif
AVStream *ostream = avformat_new_stream(vs->format_ctx, encoder);