1
1

agent_connect_unix: make sure there's a trailing zero

... if the path name was too long. Reported by Coverity CID 89801.
Этот коммит содержится в:
Daniel Stenberg 2014-12-23 20:03:50 +01:00
родитель 8a731d6217
Коммит 637c90959b

Просмотреть файл

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2009 by Daiki Ueno * Copyright (c) 2009 by Daiki Ueno
* Copyright (C) 2014 by Daniel Stenberg * Copyright (C) 2010-2014 by Daniel Stenberg
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, * Redistribution and use in source and binary forms,
@ -159,6 +159,8 @@ agent_connect_unix(LIBSSH2_AGENT *agent)
s_un.sun_family = AF_UNIX; s_un.sun_family = AF_UNIX;
strncpy (s_un.sun_path, path, sizeof s_un.sun_path); strncpy (s_un.sun_path, path, sizeof s_un.sun_path);
s_un.sun_path[sizeof(s_un.sun_path)-1]=0; /* make sure there's a trailing
zero */
if (connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) { if (connect(agent->fd, (struct sockaddr*)(&s_un), sizeof s_un) != 0) {
close (agent->fd); close (agent->fd);
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL, return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,