[PATCH 4/5] check for overflow when setting HTTP_USER_AGENT

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 4/5] check for overflow when setting HTTP_USER_AGENT

Andrew Gregory
gcc7 issues a warning about a potential overflow if left unchecked.

Signed-off-by: Andrew Gregory <[hidden email]>
---
 src/pacman/pacman.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 605aec3e..11b7e6f0 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -271,10 +271,15 @@ static void setuseragent(void)
 {
  char agent[101];
  struct utsname un;
+ int len;
 
  uname(&un);
- snprintf(agent, 100, "pacman/%s (%s %s) libalpm/%s",
+ len = snprintf(agent, 100, "pacman/%s (%s %s) libalpm/%s",
  PACKAGE_VERSION, un.sysname, un.machine, alpm_version());
+ if(len >= 100) {
+ pm_printf(ALPM_LOG_WARNING, _("HTTP_USER_AGENT truncated\n"));
+ }
+
  setenv("HTTP_USER_AGENT", agent, 0);
 }
 
--
2.12.2
Loading...