From: Ian Campbell Subject: Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets Date: Wed, 2 Jul 2014 14:02:38 +0100 Message-ID: <1404306158.5562.66.camel@kazak.uk.xensource.com> References: <1402622331-4282-1-git-send-email-mcgrof@do-not-panic.com> <1402622331-4282-3-git-send-email-mcgrof@do-not-panic.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X2KBQ-0006SE-3l for xen-devel@lists.xenproject.org; Wed, 02 Jul 2014 13:02:44 +0000 In-Reply-To: <1402622331-4282-3-git-send-email-mcgrof@do-not-panic.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: "Luis R. Rodriguez" Cc: xen-devel@lists.xenproject.org, "Luis R. Rodriguez" List-Id: xen-devel@lists.xenproject.org On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote: > +int xs_validate_active_socket(const char *connect_to) > +{ > + char sock[30]; > + > + /* We have to null terminate the socket path */ > + memset(sock, '\0', sizeof(sock)); > + memcpy(sock, connect_to, strlen(connect_to)); This risks overrunning sock if connect_to is longer than 30 characters. But your use of strlen suggests that connect_to is already NULL terminated, so what is this for? > + if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) && > + (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) { Given that sock (or connect_to) is NULL terminated, why strncmp and not the straightforward strcmp? As it is I think your code would accept e.g. /var/run/xenstored/socketwibble, no? Is it common in systemd support to validate the input socket's path in this way? As opposed to trusting that the systemd unit file is correct. > +static void xen_claim_active_sockets(int **psock, int **pro_sock) > +{ > + int *sock, *ro_sock; > + const char *soc_str = xs_daemon_socket(); > + const char *soc_str_ro = xs_daemon_socket_ro(); > + int n; > + > + n = sd_listen_fds(0); > + if (n <= 0) { > + sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n" > + "ERRNO=%i", > + strerror(errno), > + errno); > + barf_perror("sd_listen_fds() failed\n"); > + } else if (n > 2) { > + fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n); > + sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n" > + "ERRNO=%d", > + strerror(EBADR), > + EBADR); > + barf_perror("sd_listen_fds() gave too many fds\n"); Need this be fatal? Ian.