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:
Gabriel M. Beddingfield
2011-11-28 17:17:00 -06:00
parent 80085d470d
commit 3e3376a4b7
2 changed files with 14 additions and 7 deletions
+10 -5
View File
@@ -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
View File
@@ -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);