the overflowing data comes from the local user.
sendcmd(int s, char *cmd, char *arg)
{
char buf[128];
sendcmd(int s, char *cmd, char *arg)
{
char buf[128];
- (void)sprintf(buf, "%s %s\n", cmd, arg != NULL ? arg : "");
- len = strlen(buf);
+ len = snprintf(buf, sizeof(buf), "%s %s\n",
+ cmd, arg != NULL ? arg : "");
+ if (len >= (int)sizeof(buf)) {
+ fprintf(stderr, "%s too long\n", cmd);
+ exit(1);
+ }
cc = write(s, buf, len);
if (cc < 0) {
perror("sendcmd: write");
cc = write(s, buf, len);
if (cc < 0) {
perror("sendcmd: write");