Introduce size limit in ftdi_get_eeprom_buf()
[libftdi] / src / ftdi.c
index fc561b5..4cc55e4 100644 (file)
@@ -2,7 +2,7 @@
                           ftdi.c  -  description
                              -------------------
     begin                : Fri Apr 4 2003
-    copyright            : (C) 2003-2010 by Intra2net AG
+    copyright            : (C) 2003-2011 by Intra2net AG and the libftdi developers
     email                : opensource@intra2net.com
  ***************************************************************************/
 
@@ -3114,7 +3114,7 @@ int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value valu
    No parameter checking is performed
 
    \param ftdi pointer to ftdi_context
-   \param value_name Enum of the value to query
+   \param value_name Enum of the value to set
    \param value to set
 
    \retval 0: all fine
@@ -3257,7 +3257,13 @@ int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size
 {
     if (!ftdi || !(ftdi->eeprom))
         ftdi_error_return(-1, "No appropriate structure");
+
+    // Only copy up to FTDI_MAX_EEPROM_SIZE bytes
+    if (size > FTDI_MAX_EEPROM_SIZE)
+        size = FTDI_MAX_EEPROM_SIZE;
+
     memcpy(buf, ftdi->eeprom->buf, size);
+
     return 0;
 }