[1/4] v4l-utils/libdvbv5: avoid crash when failed to get a channel name
Commit Message
From: Akihiro Tsukada <tskd08@gmail.com>
Signed-off-by: Akihiro Tsukada <tskd08@gmail.com>
---
lib/libdvbv5/dvb-file.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
Comments
Em Wed, 08 Oct 2014 21:09:38 +0900
tskd08@gmail.com escreveu:
> From: Akihiro Tsukada <tskd08@gmail.com>
>
> Signed-off-by: Akihiro Tsukada <tskd08@gmail.com>
> ---
> lib/libdvbv5/dvb-file.c | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/lib/libdvbv5/dvb-file.c b/lib/libdvbv5/dvb-file.c
> index 27d9a63..bcb1762 100644
> --- a/lib/libdvbv5/dvb-file.c
> +++ b/lib/libdvbv5/dvb-file.c
> @@ -1121,20 +1121,21 @@ static int get_program_and_store(struct dvb_v5_fe_parms_priv *parms,
> if (rc)
> dvb_logerr("Couldn't get frontend props");
> }
> - if (!*channel) {
> - r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
> - if (r < 0)
> - dvb_perror("asprintf");
> - if (parms->p.verbose)
> - dvb_log("Storing as: '%s'", channel);
> - }
I prefer to keep the code as is and fix the caller that would be passing
a null pointer here, replacing it for an empty channel name.
> for (j = 0; j < parms->n_props; j++) {
> entry->props[j].cmd = parms->dvb_prop[j].cmd;
> entry->props[j].u.data = parms->dvb_prop[j].u.data;
>
> - if (!*channel && entry->props[j].cmd == DTV_FREQUENCY)
> + if ((!channel || !*channel) &&
> + entry->props[j].cmd == DTV_FREQUENCY)
> freq = parms->dvb_prop[j].u.data;
> }
> + if (!channel || !*channel) {
> + r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
> + if (r < 0)
> + dvb_perror("asprintf");
> + if (parms->p.verbose)
> + dvb_log("Storing as: '%s'", channel);
> + }
> entry->n_props = parms->n_props;
> entry->channel = channel;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
@@ -1121,20 +1121,21 @@ static int get_program_and_store(struct dvb_v5_fe_parms_priv *parms,
if (rc)
dvb_logerr("Couldn't get frontend props");
}
- if (!*channel) {
- r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
- if (r < 0)
- dvb_perror("asprintf");
- if (parms->p.verbose)
- dvb_log("Storing as: '%s'", channel);
- }
for (j = 0; j < parms->n_props; j++) {
entry->props[j].cmd = parms->dvb_prop[j].cmd;
entry->props[j].u.data = parms->dvb_prop[j].u.data;
- if (!*channel && entry->props[j].cmd == DTV_FREQUENCY)
+ if ((!channel || !*channel) &&
+ entry->props[j].cmd == DTV_FREQUENCY)
freq = parms->dvb_prop[j].u.data;
}
+ if (!channel || !*channel) {
+ r = asprintf(&channel, "%.2fMHz#%d", freq/1000000., service_id);
+ if (r < 0)
+ dvb_perror("asprintf");
+ if (parms->p.verbose)
+ dvb_log("Storing as: '%s'", channel);
+ }
entry->n_props = parms->n_props;
entry->channel = channel;