mirror of
https://github.com/openharmony/third_party_tinyalsa.git
synced 2026-07-19 23:33:30 -04:00
tinycap, tinyplay: Check *argv before dereferencing.
In several places, argv is incremented and *argv is dereferenced
without checking to see if it is valid to do so. This could lead to a
buffer overrun if the user provides invalid parameters.
This patch generally changes this:
if (strcmp(*argv, "-r") == 0) {
argv++;
rate = atoi(*argv);
}
argv++;
To this:
if (strcmp(*argv, "-r") == 0) {
argv++;
if (*argv)
rate = atoi(*argv);
}
if (*argv)
argv++;
Signed-off-by: Gabriel M. Beddingfield <gabrbedd@ti.com>
This commit is contained in:
@@ -93,18 +93,23 @@ int main(int argc, char **argv)
|
||||
while (*argv) {
|
||||
if (strcmp(*argv, "-d") == 0) {
|
||||
argv++;
|
||||
device = atoi(*argv);
|
||||
if (*argv)
|
||||
device = atoi(*argv);
|
||||
} else if (strcmp(*argv, "-c") == 0) {
|
||||
argv++;
|
||||
channels = atoi(*argv);
|
||||
if (*argv)
|
||||
channels = atoi(*argv);
|
||||
} else if (strcmp(*argv, "-r") == 0) {
|
||||
argv++;
|
||||
rate = atoi(*argv);
|
||||
if (*argv)
|
||||
rate = atoi(*argv);
|
||||
} else if (strcmp(*argv, "-b") == 0) {
|
||||
argv++;
|
||||
bits = atoi(*argv);
|
||||
if (*argv)
|
||||
bits = atoi(*argv);
|
||||
}
|
||||
argv++;
|
||||
if (*argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
header.riff_id = ID_RIFF;
|
||||
|
||||
+4
-2
@@ -79,9 +79,11 @@ int main(int argc, char **argv)
|
||||
while (*argv) {
|
||||
if (strcmp(*argv, "-d") == 0) {
|
||||
argv++;
|
||||
device = atoi(*argv);
|
||||
if (*argv)
|
||||
device = atoi(*argv);
|
||||
}
|
||||
argv++;
|
||||
if (*argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
fread(&header, sizeof(struct wav_header), 1, file);
|
||||
|
||||
Reference in New Issue
Block a user