}
}
- strncpy(io.u2c_uuid_string, uuidString, sizeof io.u2c_uuid_string);
+ strncpy(io.u2c_uuid_string, uuidString, sizeof io.u2c_uuid_string - 1);
+ io.u2c_uuid_string[sizeof io.u2c_uuid_string - 1] = '\0';
if (ioctl(fd, VMCI_SOCKETS_UUID_2_CID, &io) < 0) {
io.u2c_context_id = VMADDR_CID_ANY;
}
*/
macInfo = gld_mac_alloc(dip);
if (!macInfo) {
- cmn_err(CE_WARN, "%s%d: Vxn_Attach: gld_mac_alloc failed",
+ cmn_err(CE_WARN, "%s%d: Vxn_Attach: gld_mac_alloc failed",
drvName, unit);
goto err_gld_mac_alloc;
}
* Get interrupt cookie
*/
if (ddi_get_iblock_cookie(dip, 0, &dp->iblockCookie) != DDI_SUCCESS) {
- cmn_err(CE_WARN, "%s%d: Vxn_Attach: ddi_get_iblock_cookie failed",
+ cmn_err(CE_WARN, "%s%d: Vxn_Attach: ddi_get_iblock_cookie failed",
drvName, unit);
goto err_get_iblock_cookie;
}
- strncpy(dp->drvName, drvName, SOLVMXNET_MAXNAME);
+ /*
+ * kmem_zalloc above memsets drvName to 0. Use array size - 1 below
+ * to ensure NUL termination.
+ */
+ strncpy(dp->drvName, drvName, sizeof dp->drvName - 1);
dp->unit = unit;
dp->dip = dip;
dp->macInfo = macInfo;
/*********************************************************
- * Copyright (C) 2011-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2011-2016,2019 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
VGAuthComm_SetTestBufferInput(VGAuthContext *ctx,
const char *buffer)
{
- VGAuthError err = VGAUTH_E_OK;
+ VGAuthError err;
+ size_t bufLen;
ctx->comm.bufTest = TRUE;
ctx->comm.bufLoc = 0;
- ctx->comm.bufLen = strlen(buffer);
- strncpy(ctx->comm.testBuffer, buffer, ctx->comm.bufLen + 1);
+ bufLen = strlen(buffer);
+
+ if (bufLen > sizeof ctx->comm.testBuffer - 1) {
+ fprintf(stderr, "Test buffer too large.\n");
+ err = VGAUTH_E_INVALID_ARGUMENT;
+ } else {
+ ctx->comm.bufLen = bufLen;
+ strncpy(ctx->comm.testBuffer, buffer, sizeof ctx->comm.testBuffer - 1);
+ ctx->comm.testBuffer[sizeof ctx->comm.testBuffer - 1] = '\0';
+ err = VGAUTH_E_OK;
+ }
return err;
}