Skip to content

Commit 1e5e511

Browse files
pseidererkuba-moo
authored andcommitted
net: pktgen: fix ctrl interface command parsing
Enable command writing without trailing '\n': - the good case $ echo "reset" > /proc/net/pktgen/pgctrl - the bad case (before the patch) $ echo -n "reset" > /proc/net/pktgen/pgctrl -bash: echo: write error: Invalid argument - with patch applied $ echo -n "reset" > /proc/net/pktgen/pgctrl Signed-off-by: Peter Seiderer <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 1c3bc2c commit 1e5e511

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/core/pktgen.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,21 +517,23 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
517517
size_t count, loff_t *ppos)
518518
{
519519
char data[128];
520+
size_t max;
520521
struct pktgen_net *pn = net_generic(current->nsproxy->net_ns, pg_net_id);
521522

522523
if (!capable(CAP_NET_ADMIN))
523524
return -EPERM;
524525

525-
if (count == 0)
526+
if (count < 1)
526527
return -EINVAL;
527528

528-
if (count > sizeof(data))
529-
count = sizeof(data);
530-
531-
if (copy_from_user(data, buf, count))
529+
max = min(count, sizeof(data) - 1);
530+
if (copy_from_user(data, buf, max))
532531
return -EFAULT;
533532

534-
data[count - 1] = 0; /* Strip trailing '\n' and terminate string */
533+
if (data[max - 1] == '\n')
534+
data[max - 1] = 0; /* strip trailing '\n', terminate string */
535+
else
536+
data[max] = 0; /* terminate string */
535537

536538
if (!strcmp(data, "stop"))
537539
pktgen_stop_all_threads(pn);

0 commit comments

Comments
 (0)