summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Ulrich Niedermann <gp@n-dimensional.de>2005-06-12 15:00:52 +0000
committerHans Ulrich Niedermann <gp@n-dimensional.de>2005-06-12 15:00:52 +0000
commita748ceffe8db5919e020fe6537ee79e542d762a4 (patch)
treef90719490d2bb8ef2f4668779bfefef60cb419e3
parent4e74efa525e93bd2c5dd370da92218f453650ddd (diff)
downloadlibgphoto2-a748ceffe8db5919e020fe6537ee79e542d762a4.tar.gz
check for list errors creating list of camlibs and abort in case of errors
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@8082 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r--libgphoto2/gphoto2-abilities-list.c18
-rw-r--r--libgphoto2/gphoto2-list.c66
2 files changed, 74 insertions, 10 deletions
diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c
index 86d526d9c..fc6da8531 100644
--- a/libgphoto2/gphoto2-abilities-list.c
+++ b/libgphoto2/gphoto2-abilities-list.c
@@ -131,12 +131,13 @@ static int
foreach_func (const char *filename, lt_ptr data)
{
CameraList *list = data;
+ int result;
gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
"Found '%s'.", filename);
- gp_list_append (list, filename, NULL);
+ result = gp_list_append (list, filename, NULL);
- return (0);
+ return ((result == GP_OK)?0:1);
}
@@ -152,6 +153,7 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
const char *filename;
CameraList *flist;
int count;
+ int ret;
lt_dlhandle lh;
CHECK_NULL (list && dir);
@@ -162,8 +164,16 @@ gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
CHECK_RESULT (gp_list_reset (flist));
lt_dlinit ();
lt_dladdsearchdir (dir);
- lt_dlforeachfile (dir, foreach_func, flist);
+ ret = lt_dlforeachfile (dir, foreach_func, flist);
lt_dlexit ();
+ if (ret != 0) {
+ gp_log (GP_LOG_ERROR, "gp-abilities-list",
+ "Internal error looking for camlibs (%d)", ret);
+ gp_context_error (context,
+ _("Internal error looking for camlibs. "
+ "(path names too long?)"));
+ return (GP_ERROR);
+ }
CHECK_RESULT (count = gp_list_count (flist));
gp_log (GP_LOG_DEBUG, "gp-abilities-list", "Found %i "
"camera drivers.", count);
@@ -371,7 +381,7 @@ gp_abilities_list_detect (CameraAbilitiesList *list,
CHECK_NULL (list && info_list && l);
- l->count = 0;
+ gp_list_reset (l);
CHECK_RESULT (info_count = gp_port_info_list_count (info_list));
diff --git a/libgphoto2/gphoto2-list.c b/libgphoto2/gphoto2-list.c
index acdd8280a..995c1a407 100644
--- a/libgphoto2/gphoto2-list.c
+++ b/libgphoto2/gphoto2-list.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "gphoto2-list.h"
+#include "gphoto2-port-log.h"
#include <stdio.h>
#include <stdlib.h>
@@ -30,6 +31,7 @@
#define CHECK_NULL(r) {if (!(r)) return (GP_ERROR_BAD_PARAMETERS);}
#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);}
+
/**
* gp_list_new:
* @list:
@@ -147,12 +149,36 @@ gp_list_append (CameraList *list, const char *name, const char *value)
if (list->count == MAX_ENTRIES)
return (GP_ERROR_NO_MEMORY);
- if (name)
- strncpy (list->entry[list->count].name, name,
- sizeof (list->entry[list->count].name));
- if (value)
- strncpy (list->entry[list->count].value, value,
- sizeof (list->entry[list->count].value));
+ if (name) {
+ /* check that the value fits */
+ const size_t buf_len = sizeof (list->entry[list->count].name);
+ const size_t str_len = strlen (name);
+ if (str_len >= buf_len) {
+ gp_log (GP_LOG_ERROR, "gphoto2-list",
+ "gp_list_append: "
+ "'name' value too long (%d >= %d)",
+ str_len, buf_len);
+ return (GP_ERROR_NO_MEMORY);
+ }
+ /* set the value */
+ strncpy (list->entry[list->count].name, name, buf_len);
+ list->entry[list->count].name[buf_len-1] = '\0';
+ }
+ if (value) {
+ /* check that the value fits */
+ const size_t buf_len = sizeof (list->entry[list->count].value);
+ const size_t str_len = strlen (value);
+ if (str_len >= buf_len) {
+ gp_log (GP_LOG_ERROR, "gphoto2-list",
+ "gp_list_append: "
+ "'value' value too long (%d >= %d)",
+ str_len, buf_len);
+ return (GP_ERROR_NO_MEMORY);
+ }
+ /* set the value */
+ strncpy (list->entry[list->count].value, value, buf_len);
+ list->entry[list->count].value[buf_len-1] = '\0';
+ }
list->count++;
@@ -281,6 +307,20 @@ gp_list_set_value (CameraList *list, int index, const char *value)
if (index < 0 || index >= list->count)
return (GP_ERROR_BAD_PARAMETERS);
+ do {
+ /* check that the value fits */
+ const size_t buf_len = sizeof (list->entry[index].value);
+ const size_t str_len = strlen (value);
+ if (str_len >= buf_len) {
+ gp_log (GP_LOG_ERROR, "gphoto2-list",
+ "gp_list_append: "
+ "'value' value too long (%d >= %d)",
+ str_len, buf_len);
+ return (GP_ERROR_NO_MEMORY);
+ }
+ } while (0);
+
+ /* set the value */
strcpy (list->entry[index].value, value);
return (GP_OK);
@@ -304,6 +344,20 @@ gp_list_set_name (CameraList *list, int index, const char *name)
if (index >= list->count)
return (GP_ERROR_BAD_PARAMETERS);
+ do {
+ /* check that the value fits */
+ const size_t buf_len = sizeof (list->entry[index].name);
+ const size_t str_len = strlen (name);
+ if (str_len >= buf_len) {
+ gp_log (GP_LOG_ERROR, "gphoto2-list",
+ "gp_list_append: "
+ "'name' value too long (%d >= %d)",
+ str_len, buf_len);
+ return (GP_ERROR_NO_MEMORY);
+ }
+ } while (0);
+
+ /* set the value */
strcpy (list->entry[index].name, name);
return (GP_OK);