mirror of
https://github.com/iustin/mt-st.git
synced 2026-01-07 12:35:19 +00:00
Fix coverity scan warnings.
* Fix the leaking `fd`. * Fix the possible overflow of strcat(). Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
22
mt.c
22
mt.c
@@ -372,7 +372,7 @@ static void version()
|
|||||||
static void usage(int explain, int exit_code)
|
static void usage(int explain, int exit_code)
|
||||||
{
|
{
|
||||||
int ind;
|
int ind;
|
||||||
char line[100];
|
int counter = 0;
|
||||||
|
|
||||||
fprintf(stderr, "usage: mt [-v] [--version] [-h] [ -f device ] command [ "
|
fprintf(stderr, "usage: mt [-v] [--version] [-h] [ -f device ] command [ "
|
||||||
"count ]\n");
|
"count ]\n");
|
||||||
@@ -380,17 +380,17 @@ static void usage(int explain, int exit_code)
|
|||||||
if (explain) {
|
if (explain) {
|
||||||
for (ind = 0; cmds[ind].cmd_name != NULL;) {
|
for (ind = 0; cmds[ind].cmd_name != NULL;) {
|
||||||
if (ind == 0)
|
if (ind == 0)
|
||||||
strcpy(line, "commands: ");
|
counter = fprintf(stderr, "commands: ");
|
||||||
else
|
else
|
||||||
strcpy(line, " ");
|
counter = fprintf(stderr, " ");
|
||||||
for (; cmds[ind].cmd_name != NULL; ind++) {
|
for ( ; cmds[ind].cmd_name != NULL; ind++) {
|
||||||
strcat(line, cmds[ind].cmd_name);
|
counter += fprintf(stderr, "%s", cmds[ind].cmd_name);
|
||||||
if (cmds[ind + 1].cmd_name != NULL)
|
if (cmds[ind+1].cmd_name != NULL)
|
||||||
strcat(line, ", ");
|
counter += fprintf(stderr, ", ");
|
||||||
else
|
else
|
||||||
strcat(line, ".");
|
counter += fprintf(stderr, ".");
|
||||||
if (strlen(line) >= 70 || cmds[ind + 1].cmd_name == NULL) {
|
if (counter >= 70 || cmds[ind+1].cmd_name == NULL) {
|
||||||
fprintf(stderr, "%s\n", line);
|
fprintf(stderr, "\n");
|
||||||
ind++;
|
ind++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -716,6 +716,8 @@ static int do_show_options(int mtfd,
|
|||||||
|
|
||||||
if ((fd = open(fname, O_RDONLY)) < 0 || read(fd, buf, 20) < 0) {
|
if ((fd = open(fname, O_RDONLY)) < 0 || read(fd, buf, 20) < 0) {
|
||||||
fprintf(stderr, "Can't read the sysfs file '%s'.\n", fname);
|
fprintf(stderr, "Can't read the sysfs file '%s'.\n", fname);
|
||||||
|
if (fd >= 0)
|
||||||
|
close(fd);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
3
stinit.c
3
stinit.c
@@ -333,8 +333,7 @@ find_pars(FILE *dbf, char *company, char *product, char *rev, devdef_tr *defs, i
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(modebuf, comptr);
|
snprintf(defstr, sizeof(defstr)/sizeof(char), "%s%s", comptr, cp);
|
||||||
strcat(modebuf, cp);
|
|
||||||
*nextdef = c;
|
*nextdef = c;
|
||||||
|
|
||||||
if (verbose > 1)
|
if (verbose > 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user