From 29bcee8b7a0623cd5e0e29df363ed82daa3a7ca2 Mon Sep 17 00:00:00 2001 From: Marcus Meissner Date: Wed, 7 Feb 2007 17:49:31 +0000 Subject: [PATCH] check some NULL ptr returns from strdup, malloc git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@9992 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/ptp2/config.c | 8 ++++++++ camlibs/ptp2/library.c | 4 ++++ camlibs/ptp2/ptpip.c | 2 ++ camlibs/ptp2/usb.c | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/camlibs/ptp2/config.c b/camlibs/ptp2/config.c index 3a576f9e8..578fcbddf 100644 --- a/camlibs/ptp2/config.c +++ b/camlibs/ptp2/config.c @@ -491,6 +491,8 @@ _put_STR(CONFIG_PUT_ARGS) { if (ret != GP_OK) return ret; propval->str = strdup (string); + if (!propval->str) + return (GP_ERROR_NO_MEMORY); return (GP_OK); } @@ -505,6 +507,8 @@ _put_AUINT8_as_CHAR_ARRAY(CONFIG_PUT_ARGS) { memset(propval,0,sizeof(PTPPropertyValue)); /* add \0 ? */ propval->a.v = malloc((strlen(value)+1)*sizeof(PTPPropertyValue)); + if (!propval->a.v) + return (GP_ERROR_NO_MEMORY); propval->a.count = strlen(value)+1; for (i=0;ia.v[i].u8 = value[i]; @@ -645,6 +649,8 @@ _put_ImageSize(CONFIG_PUT_ARGS) { if(ret != GP_OK) return ret; propval->str = strdup (value); + if (!propval->str) + return (GP_ERROR_NO_MEMORY); return(GP_OK); } @@ -1621,6 +1627,8 @@ _put_STR_as_time(CONFIG_PUT_ARGS) { /* 20020101T123400.0 is returned by the HP Photosmart */ sprintf(asctime,"%04d%02d%02dT%02d%02d%02d.0",pxtm->tm_year+1900,pxtm->tm_mon+1,pxtm->tm_mday,pxtm->tm_hour,pxtm->tm_min,pxtm->tm_sec); propval->str = strdup(asctime); + if (!propval->str) + return (GP_ERROR_NO_MEMORY); return (GP_OK); } diff --git a/camlibs/ptp2/library.c b/camlibs/ptp2/library.c index 57fcff590..6a1c9b93e 100644 --- a/camlibs/ptp2/library.c +++ b/camlibs/ptp2/library.c @@ -136,6 +136,8 @@ add_special_file (char *name, getfunc_t getfunc, putfunc_t putfunc) { special_files = malloc (sizeof(special_files[0])); special_files[nrofspecial_files].name = strdup(name); + if (!special_files[nrofspecial_files].name) + return (GP_ERROR_NO_MEMORY); special_files[nrofspecial_files].putfunc = putfunc; special_files[nrofspecial_files].getfunc = getfunc; nrofspecial_files++; @@ -2548,6 +2550,8 @@ ptp_mtp_parse_metadata ( *end = '\0'; content = strdup(begin); *end = '<'; + if (!content) + continue; gp_log (GP_LOG_DEBUG, "ptp2", "found tag %s, content %s", propname, content); ret = ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd); if (ret != PTP_RC_OK) { diff --git a/camlibs/ptp2/ptpip.c b/camlibs/ptp2/ptpip.c index 60ceaf921..6f47ee9be 100644 --- a/camlibs/ptp2/ptpip.c +++ b/camlibs/ptp2/ptpip.c @@ -597,6 +597,8 @@ ptp_ptpip_connect (PTPParams* params, const char *address) { if (NULL == strchr (address,':')) return GP_ERROR_BAD_PARAMETERS; addr = strdup (address); + if (!addr) + return GP_ERROR_NO_MEMORY; s = strchr (addr,':'); *s = '\0'; p = strchr (s+1,':'); port = 15740; diff --git a/camlibs/ptp2/usb.c b/camlibs/ptp2/usb.c index 498a193f6..f5c80a6b2 100644 --- a/camlibs/ptp2/usb.c +++ b/camlibs/ptp2/usb.c @@ -143,6 +143,8 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, if (usecontext) progressid = gp_context_progress_start (context, (size/CONTEXT_BLOCK_SIZE), _("Uploading...")); bytes = malloc (4096); + if (!bytes) + return PTP_RC_GeneralError; /* if everything OK send the rest */ bytes_left_to_transfer = size-datawlen; ret = PTP_RC_OK; @@ -248,6 +250,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) } if (usbdata.length == 0xffffffffU) { unsigned char *data = malloc (PTP_USB_BULK_HS_MAX_PACKET_LEN); + if (!data) return PTP_RC_GeneralError; /* stuff data directly to passed data handler */ while (1) { unsigned long written; @@ -281,6 +284,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) if (surplen >= PTP_USB_BULK_HDR_LEN) { params->response_packet = malloc(surplen); + if (!params->response_packet) return PTP_RC_GeneralError; memcpy(params->response_packet, (uint8_t *) &usbdata + packlen, surplen); params->response_packet_size = surplen; @@ -313,6 +317,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) retry: oldsize = 0; data = malloc(READLEN); + if (!data) return PTP_RC_GeneralError; bytes_to_read = len - (rlen - PTP_USB_BULK_HDR_LEN); usecontext = (bytes_to_read > CONTEXT_BLOCK_SIZE); ret = PTP_RC_OK;