Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24d22077 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Takashi Iwai
Browse files

ALSA: opti9xx: fix format string overflow warning



We pass a long name from "codec->pcm->name" into the longname
string of the same length:

sound/isa/opti9xx/miro.c: In function 'snd_miro_probe':
sound/isa/opti9xx/miro.c:1356:39: error: '%s' directive writing up to 79 bytes into a region of size between 35 and 72 [-Werror=format-overflow=]
  sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
                                       ^~
sound/isa/opti9xx/miro.c:1356:26: note: using the range [0, 4294967295] for directive argument
  sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/isa/opti9xx/miro.c:1356:2: note: 'sprintf' output between 32 and 185 bytes into a destination of size 80
  sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",

There is no easy way to avoid the theoretical overflow in this case,
but using snprintf() will turn it into a harmless truncation.

Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 003d3e70
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1353,7 +1353,8 @@ static int snd_miro_probe(struct snd_card *card)
	}

	strcpy(card->driver, "miro");
	sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
	snprintf(card->longname, sizeof(card->longname),
		 "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
		 card->shortname, miro->name, codec->pcm->name,
		 miro->wss_base + 4, miro->irq, miro->dma1, miro->dma2);

+8 −6
Original line number Diff line number Diff line
@@ -879,11 +879,13 @@ static int snd_opti9xx_probe(struct snd_card *card)
	strcpy(card->driver, chip->name);
	sprintf(card->shortname, "OPTi %s", card->driver);
#if defined(CS4231) || defined(OPTi93X)
	sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
	snprintf(card->longname, sizeof(card->longname),
		 "%s, %s at 0x%lx, irq %d, dma %d&%d",
		 card->shortname, codec->pcm->name,
		 chip->wss_base + 4, irq, dma1, xdma2);
#else
	sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
	snprintf(card->longname, sizeof(card->longname),
		 "%s, %s at 0x%lx, irq %d, dma %d",
		 card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
		 dma1);
#endif	/* CS4231 || OPTi93X */