Skip to contentSkip to conversation

compress: Prevent divide-by-zero faults in get_hpointer()

PATCH Applied Richard Fitzgerald 1 participant 2 messages Feb 10, 2013 – Feb 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 13/14 compress: Prevent divide-by-zero faults in get_hpointer()

Do not assume that the returned snd_compr_avail contains a snd_compr_tstamp with a valid sampling_rate. Check for zero before attempting to use it.

compress.c +9 -4
index cfd0219..c0e81a3 100644
@@ -297,10 +297,15 @@ int compress_get_hpointer(struct compress *compress,
 	if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail))
 		return oops(compress, errno, "cannot get avail");
 	*avail = (unsigned int)kavail.avail;
-	time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
-	tstamp->tv_sec = time;
-	time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
-	tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	if (kavail.tstamp.sampling_rate != 0) {
+		time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
+		tstamp->tv_sec = time;
+		time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
+		tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+	} else {
+		tstamp->tv_sec = 0;
+		tstamp->tv_nsec = 0;
+	}
 	return 0;
 }
 
Signature · 1 line
1.7.2.5
#1 lore raw

This patch is now obsolete - an equivalent change has already been applied So no rebased version.