From 1a7967bea5c200bdfb747a71d87d75a4cb382ab9 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 15 May 1999 17:06:43 +0000 Subject: 1999-05-15 Roland McGrath * hashexec.c (check_hashbang): Trim trailing blanks after interpreter argument. --- exec/hashexec.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/exec/hashexec.c b/exec/hashexec.c index 665724ad..4b8eae4f 100644 --- a/exec/hashexec.c +++ b/exec/hashexec.c @@ -1,5 +1,5 @@ /* GNU Hurd standard exec server, #! script execution support. - Copyright (C) 1995, 96, 97, 98 Free Software Foundation, Inc. + Copyright (C) 1995, 96, 97, 98, 99 Free Software Foundation, Inc. Written by Roland McGrath. This file is part of the GNU Hurd. @@ -151,20 +151,30 @@ check_hashbang (struct execdata *e, interp = strsep (&p, " \t"); if (p) - /* Skip remaining blanks, and the rest of the line is the argument. */ { + /* Skip remaining blanks, and the rest of the line is the argument. */ p += strspn (p, " \t"); arg = p; len = interp_len - (arg - ibuf); - } - else - /* There is no argument. */ - len = 0; - if (len == 0) - arg = NULL; + if (len == 0) + arg = NULL; + else + { + size_t i = len - 1; + /* Trim trailing blanks after the argument. */ + while (arg[i] == ' ' || arg[i] == '\t') + --i; + arg[i] = '\0'; + len = i + 2; /* Include the terminating null. */ + } + } else - ++len; /* Include the terminating null. */ + { + /* There is no argument. */ + arg = NULL; + len = 0; + } interp_len = strlen (interp) + 1; -- cgit v1.2.3