From befc0d83cdcdd85cb699347873d9d3ac0454162f Mon Sep 17 00:00:00 2001 From: Fredrik Date: Mon, 14 Jan 2002 21:30:20 +0000 Subject: [PATCH] more carefull string size handling. git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@3876 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/canon/canon.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/camlibs/canon/canon.c b/camlibs/canon/canon.c index 4dd2be203..31f443566 100644 --- a/camlibs/canon/canon.c +++ b/camlibs/canon/canon.c @@ -811,8 +811,7 @@ gphoto2canonpath (Camera *camera, const char *path, GPContext *context) } } - strcpy (tmp, camera->pl->cached_drive); - strcat (tmp, path); + snprintf (tmp, sizeof(tmp), "%s%s", camera->pl->cached_drive, path); /* replace all slashes by backslashes */ for (p = tmp; *p != '\0'; p++) { @@ -846,11 +845,19 @@ canon2gphotopath (Camera *camera, const char *path) char *p; if (!((path[1] == ':') && (path[2] == '\\'))) { + GP_DEBUG ("canon2gphotopath called on invalid canon path '%s'", path); + return NULL; + } + + /* 3 is D: plus NULL byte */ + if (strlen (path) - 3 > sizeof (tmp)) { + GP_DEBUG ("canon2gphotopath called on too long canon path (%i bytes): %s", + strlen (path), path); return NULL; } - p = strchr(path, ':') + 1; - strcpy (tmp, p); + /* path is something like D:\FOO, we want what is after the colon */ + strcpy (tmp, path + 2); /* replace backslashes by slashes */ for (p = tmp; *p != '\0'; p++) {