Increase buffer length in simplified transaction helper functions,

and check max length in kenwood_cmd(). This fixes an overrun with
long commands like in th_set_freq().
Patch from Charles, AA1VS, +edit.


git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2976 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.13
Stéphane Fillod, F8CFE 2010-09-13 07:38:43 +00:00
rodzic 28844e674f
commit e417dd2dcd
1 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -168,22 +168,27 @@ extern const struct rig_caps ts480_caps;
/* use when not interested in the answer, but want to check its len */ /* use when not interested in the answer, but want to check its len */
static int inline kenwood_simple_transaction(RIG *rig, const char *cmd, size_t expected) static int inline kenwood_simple_transaction(RIG *rig, const char *cmd, size_t expected)
{ {
char buf[10]; char buf[20];
return kenwood_safe_transaction(rig, cmd, buf, 10, expected); return kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), expected);
} }
/* no answer needed at all */ /* no answer needed at all */
static int inline kenwood_simple_cmd(RIG *rig, const char *cmd) static int inline kenwood_simple_cmd(RIG *rig, const char *cmd)
{ {
char buf[10]; char buf[20];
return kenwood_safe_transaction(rig, cmd, buf, 10, 0); return kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), 0);
} }
/* answer is the same as the command */ /* answer is the same as the command */
static int inline kenwood_cmd(RIG *rig, const char *cmd) static int inline kenwood_cmd(RIG *rig, const char *cmd)
{ {
char buf[10]; char buf[20];
return kenwood_safe_transaction(rig, cmd, buf, 10, strlen(cmd) + 1); int lenz = strlen(cmd)+1;
if (lenz > sizeof(buf))
return -RIG_ENOMEM;
else
return kenwood_safe_transaction(rig, cmd, buf, sizeof(buf), lenz);
} }
#endif /* _KENWOOD_H */ #endif /* _KENWOOD_H */