From: Frank Lahm Date: Wed, 20 Jul 2011 09:28:19 +0000 (+0200) Subject: Abbreviate Netatalk in version string as necessary so that the version number isn... X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=9e1a1ca22bc8a8aa5dd26703e0d4a7677930e092 Abbreviate Netatalk in version string as necessary so that the version number isn't cut off and the whole string fits within the 16 bytes machine type buffer --- diff --git a/etc/afpd/status.c b/etc/afpd/status.c index ae51d26e..f7455a0e 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -128,15 +128,27 @@ static void status_machine(char *data) #ifdef AFS const char *machine = "afs"; #else /* !AFS */ - const char *machine = "Netatalk %s"; + const char *machine = "Netatalk%s"; #endif /* AFS */ char buf[AFPSTATUS_MACHLEN+1]; memcpy(&status, start + AFPSTATUS_MACHOFF, sizeof(status)); data += ntohs( status ); - // len = strlen( machine ); - len = snprintf(buf, AFPSTATUS_MACHLEN+1, machine, VERSION); + if ((strlen(machine) + strlen(VERSION)) <= 16) { + len = snprintf(buf, AFPSTATUS_MACHLEN + 1, machine, VERSION); + } else { + if (strlen(VERSION) > 16) { + len = snprintf(buf, AFPSTATUS_MACHLEN + 1, VERSION); + } else { + (void)snprintf(buf, AFPSTATUS_MACHLEN + 1, machine, ""); + (void)snprintf(buf + AFPSTATUS_MACHLEN - strlen(VERSION), + strlen(VERSION) + 1, + VERSION); + len = AFPSTATUS_MACHLEN; + } + } + *data++ = len; memcpy( data, buf, len ); data += len;