On Thu 25 July 2013 15:09:33 Gregor Jasny wrote:
> Detected by Coverity.
> 
> Signed-off-by: Gregor Jasny <gja...@googlemail.com>
> CC: Hans Verkuil <hverk...@xs4all.nl>

Reviewed-by: Hans Verkuil <hans.verk...@cisco.com>

Thanks!

        Hans

> ---
>  utils/rds-ctl/rds-ctl.cpp | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp
> index a9fe2a8..74972eb 100644
> --- a/utils/rds-ctl/rds-ctl.cpp
> +++ b/utils/rds-ctl/rds-ctl.cpp
> @@ -762,13 +762,11 @@ static int parse_cl(int argc, char **argv)
>               params.options[(int)opt] = 1;
>               switch (opt) {
>               case OptSetDevice:
> -                     strncpy(params.fd_name, optarg, 80);
> +                     strncpy(params.fd_name, optarg, sizeof(params.fd_name));
>                       if (optarg[0] >= '0' && optarg[0] <= '9' && 
> strlen(optarg) <= 3) {
> -                             static char newdev[20];
> -
> -                             sprintf(newdev, "/dev/radio%s", optarg);
> -                             strncpy(params.fd_name, newdev, 20);
> +                             snprintf(params.fd_name, 
> sizeof(params.fd_name), "/dev/radio%s", optarg);
>                       }
> +                     params.fd_name[sizeof(params.fd_name) - 1] = '\0';
>                       break;
>               case OptSetFreq:
>                       params.freq = strtod(optarg, NULL);
> @@ -786,7 +784,8 @@ static int parse_cl(int argc, char **argv)
>               {
>                       if (access(optarg, F_OK) != -1) {
>                               params.filemode_active = true;
> -                             strncpy(params.fd_name, optarg, 80);
> +                             strncpy(params.fd_name, optarg, 
> sizeof(params.fd_name));
> +                             params.fd_name[sizeof(params.fd_name) - 1] = 
> '\0';
>                       } else {
>                               fprintf(stderr, "Unable to open file: %s\n", 
> optarg);
>                               return -1;
> @@ -1006,7 +1005,8 @@ int main(int argc, char **argv)
>                       fprintf(stderr, "No RDS-capable device found\n");
>                       exit(1);
>               }
> -             strncpy(params.fd_name, devices[0].c_str(), 80);
> +             strncpy(params.fd_name, devices[0].c_str(), 
> sizeof(params.fd_name));
> +             params.fd_name[sizeof(params.fd_name) - 1] = '\0';
>               printf("Using device: %s\n", params.fd_name);
>       }
>       if ((fd = test_open(params.fd_name, O_RDONLY | O_NONBLOCK)) < 0) {
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to