From 2cf6edf4eff7231fad4c548e27ad814faeafe894 Mon Sep 17 00:00:00 2001 From: Renato Silva Date: Tue, 31 Mar 2015 21:18:46 +0200 Subject: [PATCH] Fix buffer size error handling in gethostname. * net.cc (cygwin_gethostname): Fix buffer size error handling. Signed-off-by: Corinna Vinschen --- winsup/cygwin/ChangeLog | 4 ++++ winsup/cygwin/net.cc | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0e23b0391..0d07bb1f7 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,7 @@ +2015-03-31 Renato Silva + + * net.cc (cygwin_gethostname): Fix buffer size error handling. + 2015-03-31 Corinna Vinschen * uinfo.cc (pwdgrp::fetch_account_from_windows): Don't allow fully diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index f9b317c0d..eaf6eb870 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -1076,7 +1076,10 @@ cygwin_gethostname (char *name, size_t len) if (!GetComputerNameExA (ComputerNameDnsFullyQualified, name, &local_len)) { - set_winsock_errno (); + if (GetLastError () == ERROR_MORE_DATA) + set_errno (ENAMETOOLONG); + else + set_winsock_errno (); __leave; } }