From: Christian Grothoff Date: Thu, 17 Jun 2010 21:12:09 +0000 (+0000) Subject: fixes X-Git-Tag: initial-import-from-subversion-38251~21348 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bed39036b47e1b820ee40d645f743e18520c4f8c;p=oweals%2Fgnunet.git fixes --- diff --git a/src/fs/fs.c b/src/fs/fs.c index ece6350ca..9ec35ed2f 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -583,11 +583,14 @@ GNUNET_FS_remove_sync_file_ (struct GNUNET_FS_Handle *h, return; } filename = get_serialization_file_name (h, ext, ent); - if (0 != UNLINK (filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - filename); - GNUNET_free (filename); + if (filename != NULL) + { + if (0 != UNLINK (filename)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "unlink", + filename); + GNUNET_free (filename); + } } @@ -614,11 +617,14 @@ remove_sync_file_in_dir (struct GNUNET_FS_Handle *h, return; } filename = get_serialization_file_name_in_dir (h, ext, uni, ent); - if (0 != UNLINK (filename)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "unlink", - filename); - GNUNET_free (filename); + if (filename != NULL) + { + if (0 != UNLINK (filename)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "unlink", + filename); + GNUNET_free (filename); + } } @@ -1030,6 +1036,8 @@ make_serialization_file_name (struct GNUNET_FS_Handle *h, if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ dn = get_serialization_file_name (h, ext, ""); + if (dn == NULL) + return NULL; if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) { @@ -1067,6 +1075,8 @@ make_serialization_file_name_in_dir (struct GNUNET_FS_Handle *h, if (0 == (h->flags & GNUNET_FS_FLAGS_PERSISTENCE)) return NULL; /* persistence not requested */ dn = get_serialization_file_name_in_dir (h, ext, uni, ""); + if (dn == NULL) + return NULL; if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (dn)) { @@ -1282,9 +1292,12 @@ GNUNET_FS_file_information_sync_ (struct GNUNET_FS_FileInformation * fi) GNUNET_free_non_null (chks); GNUNET_free_non_null (ksks); fn = get_serialization_file_name (fi->h, GNUNET_FS_SYNC_PATH_FILE_INFO, fi->serialization); - if (0 != UNLINK (fn)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); - GNUNET_free (fn); + if (NULL != fn) + { + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + GNUNET_free (fn); + } GNUNET_free (fi->serialization); fi->serialization = NULL; } @@ -1748,11 +1761,20 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc) } fn = GNUNET_DISK_mktemp (dir); GNUNET_free (dir); + if (fn == NULL) + return; dc->serialization = get_serialization_short_name (fn); } else { fn = get_download_sync_filename (dc, dc->serialization, ""); + if (fn == NULL) + { + GNUNET_free (dc->serialization); + dc->serialization = NULL; + GNUNET_free (fn); + return; + } } wh = GNUNET_BIO_write_open (fn); if (wh == NULL) @@ -2226,19 +2248,22 @@ deserialize_search_result (void *cls, drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_DOWNLOAD, download); - deserialize_download (sc->h, - drh, - NULL, - sr, - download); - if (GNUNET_OK != - GNUNET_BIO_read_close (drh, &emsg)) + if (drh != NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-download `%s': %s\n"), - download, - emsg); - GNUNET_free (emsg); + deserialize_download (sc->h, + drh, + NULL, + sr, + download); + if (GNUNET_OK != + GNUNET_BIO_read_close (drh, &emsg)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume sub-download `%s': %s\n"), + download, + emsg); + GNUNET_free (emsg); + } } GNUNET_free (download); } @@ -2247,18 +2272,21 @@ deserialize_search_result (void *cls, drh = get_read_handle (sc->h, GNUNET_FS_SYNC_PATH_CHILD_SEARCH, update_srch); - deserialize_search (sc->h, - drh, - sr, - update_srch); - if (GNUNET_OK != - GNUNET_BIO_read_close (drh, &emsg)) + if (drh != NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to resume sub-search `%s': %s\n"), - update_srch, - emsg); - GNUNET_free (emsg); + deserialize_search (sc->h, + drh, + sr, + update_srch); + if (GNUNET_OK != + GNUNET_BIO_read_close (drh, &emsg)) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + _("Failed to resume sub-search `%s': %s\n"), + update_srch, + emsg); + GNUNET_free (emsg); + } } GNUNET_free (update_srch); } @@ -2821,7 +2849,8 @@ deserialize_search_file (void *cls, return GNUNET_OK; } sc = deserialize_search (h, rh, NULL, ser); - sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); + if (sc != NULL) + sc->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, sc); GNUNET_free (ser); if (GNUNET_OK != GNUNET_BIO_read_close (rh, &emsg)) diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 1982153a1..b27aef8cd 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -1647,7 +1647,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, struct GNUNET_FS_ProgressInfo pi; struct GNUNET_FS_DownloadContext *dc; - if ( (sr != NULL) && + if ( (sr == NULL) || (sr->download != NULL) ) { GNUNET_break (0); diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index e8b97bb19..10be6f459 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c @@ -213,6 +213,7 @@ advertisement_cont (void *cls, &ac->nb->ns_purpose, &ac->nb->ns_signature)); pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); + GNUNET_assert (pk != NULL); GNUNET_CRYPTO_rsa_key_get_public (pk, &ac->nb->keyspace); GNUNET_CRYPTO_hash (&ac->nb->keyspace, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index a7aa695f3..e7ebeac82 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c @@ -725,6 +725,7 @@ hash_for_index_cb (void *cls, return; } fn = GNUNET_STRINGS_filename_expand (p->filename); + GNUNET_assert (fn != NULL); slen = strlen (fn) + 1; if (slen > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) { @@ -1369,6 +1370,7 @@ publish_ksk_cont (void *cls, &iv, &pkc->cpy[1]); pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&key); + GNUNET_assert (NULL != pk); GNUNET_CRYPTO_rsa_key_get_public (pk, &pkc->cpy->keyspace); GNUNET_CRYPTO_hash (&pkc->cpy->keyspace, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index ea61aa0f9..21fd7e8f1 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c @@ -1149,6 +1149,7 @@ GNUNET_FS_search_start_searching_ (struct GNUNET_FS_SearchContext *sc) keyword = &sc->uri->data.ksk.keywords[i][1]; GNUNET_CRYPTO_hash (keyword, strlen (keyword), &hc); pk = GNUNET_CRYPTO_rsa_key_create_from_hash (&hc); + GNUNET_assert (pk != NULL); GNUNET_CRYPTO_rsa_key_get_public (pk, &pub); GNUNET_CRYPTO_rsa_key_free (pk); GNUNET_CRYPTO_hash (&pub, @@ -1335,6 +1336,8 @@ GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, { struct GNUNET_FS_SearchContext *ret; ret = search_start (h, uri, anonymity, options, cctx, NULL); + if (ret == NULL) + return NULL; ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_search_signal_suspend_, ret); return ret; } diff --git a/src/fs/fs_unindex.c b/src/fs/fs_unindex.c index b69610409..474e791d9 100644 --- a/src/fs/fs_unindex.c +++ b/src/fs/fs_unindex.c @@ -307,6 +307,14 @@ unindex_finish (void *cls, uc->client = GNUNET_CLIENT_connect (uc->h->sched, "fs", uc->h->cfg); + if (uc->client == NULL) + { + uc->state = UNINDEX_STATE_ERROR; + uc->emsg = GNUNET_strdup (_("Failed to connect to FS service for unindexing.")); + GNUNET_FS_unindex_sync_ (uc); + signal_unindex_error (uc); + return; + } req.header.size = htons (sizeof (struct UnindexMessage)); req.header.type = htons (GNUNET_MESSAGE_TYPE_FS_UNINDEX); req.reserved = 0; diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 0226a340e..6123ecfef 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -263,7 +263,6 @@ run (void *cls, _("Could not initialize `%s' subsystem.\n"), "FS"); GNUNET_FS_uri_destroy (uri); - GNUNET_FS_stop (ctx); ret = 1; return; } diff --git a/src/fs/gnunet-service-fs_indexing.c b/src/fs/gnunet-service-fs_indexing.c index 630a78b10..d6654bcdc 100644 --- a/src/fs/gnunet-service-fs_indexing.c +++ b/src/fs/gnunet-service-fs_indexing.c @@ -358,6 +358,12 @@ GNUNET_FS_handle_index_start (void *cls, } ism = (const struct IndexStartMessage*) message; fn = GNUNET_STRINGS_filename_expand ((const char*) &ism[1]); + if (fn == NULL) + { + GNUNET_SERVER_receive_done (client, + GNUNET_SYSERR); + return; + } dev = ntohl (ism->device); ino = GNUNET_ntohll (ism->inode); ism = (const struct IndexStartMessage*) message; diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 6292e029e..980f142c5 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -458,7 +458,8 @@ struct GNUNET_DISK_DirectoryIterator; * * @param cls closure * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to - * get called on the next entry (or finish cleanly) + * get called on the next entry (or finish cleanly); + * NULL on error (will be the last call in that case) * @param filename complete filename (absolute path) * @param dirname directory name (absolute path) */ diff --git a/src/nat/libnatpmp/getgateway.c b/src/nat/libnatpmp/getgateway.c index ac4ac4c2e..d948669ec 100644 --- a/src/nat/libnatpmp/getgateway.c +++ b/src/nat/libnatpmp/getgateway.c @@ -105,9 +105,9 @@ getdefaultgateway (int *af, uint8_t addr[16]) if (line > 0) { p = buf; - while (*p && !isspace (*p)) + while (*p && !isspace ( (unsigned char) *p)) p++; - while (*p && isspace (*p)) + while (*p && isspace ( (unsigned char) *p)) p++; for (i = 0; i < 16; i++) { diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 33eda8a0d..a73c64da0 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -1089,6 +1089,13 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) return; } data = GNUNET_malloc_large (frstat.st_size); + if (data == NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to read friends list from `%s': out of memory\n"), fn); + GNUNET_free (fn); + return; + } if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size)) { diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c index 5d2d616e8..82deadb92 100644 --- a/src/transport/transport_api_blacklist.c +++ b/src/transport/transport_api_blacklist.c @@ -178,6 +178,7 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br) br->client = GNUNET_CLIENT_connect (br->sched, "transport", br->cfg); + GNUNET_assert (br->client != NULL); br->th = GNUNET_CLIENT_notify_transmit_ready (br->client, sizeof (struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 79e31246a..003696a48 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -180,6 +180,8 @@ GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile) if (logfile == NULL) return GNUNET_OK; fn = GNUNET_STRINGS_filename_expand (logfile); + if (NULL == fn) + return GNUNET_SYSERR; dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)); altlog = FOPEN (fn, "a"); if (altlog == NULL) @@ -374,7 +376,10 @@ mylog (enum GNUNET_ErrorType kind, time (&timetmp); memset (date, 0, DATE_STR_SIZE); tmptr = localtime (&timetmp); - strftime (date, DATE_STR_SIZE, "%b %d %H:%M:%S", tmptr); + if (NULL != tmptr) + strftime (date, DATE_STR_SIZE, "%b %d %H:%M:%S", tmptr); + else + strcpy (date, "localtime error"); if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && (last_bulk_time.value != 0) && (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) diff --git a/src/util/configuration.c b/src/util/configuration.c index b8b6e49cd..85c17cb7d 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -176,6 +176,8 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, char *fn; fn = GNUNET_STRINGS_filename_expand (filename); + if (fn == NULL) + return GNUNET_SYSERR; dirty = cfg->dirty; /* back up value! */ if (NULL == (fp = FOPEN (fn, "r"))) { @@ -302,6 +304,8 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, char *pos; fn = GNUNET_STRINGS_filename_expand (filename); + if (fn == NULL) + return GNUNET_SYSERR; GNUNET_DISK_directory_create_for_file (fn); if (NULL == (fp = FOPEN (fn, "w"))) { diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 6257ea30a..6e8fc7837 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -433,6 +433,14 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, } /* Alloc block */ bf->bitArray = GNUNET_malloc_large (size); + if (bf->bitArray == NULL) + { + if (bf->fh != NULL) + GNUNET_DISK_file_close (bf->fh); + GNUNET_free_non_null (bf->filename); + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; memset (bf->bitArray, 0, bf->bitArraySize); @@ -505,6 +513,11 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, bf->filename = NULL; bf->fh = NULL; bf->bitArray = GNUNET_malloc_large (size); + if (bf->bitArray == NULL) + { + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; if (data != NULL) diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index 2c4daee18..582006530 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -779,6 +779,8 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, GNUNET_assert (size <= sizeof (GNUNET_HashCode)); pubkey = public2PrivateKey (publicKey); + if (pubkey == NULL) + return GNUNET_SYSERR; isize = size; GNUNET_assert (0 == gcry_mpi_scan (&val, GCRYMPI_FMT_USG, block, isize, &isize)); diff --git a/src/util/disk.c b/src/util/disk.c index e3a58531b..bcede53e4 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -346,6 +346,8 @@ GNUNET_DISK_get_blocks_available (const char *part) char *path; path = GNUNET_STRINGS_filename_expand (part); + if (path == NULL) + return -1; memcpy (szDrive, path, 3); GNUNET_free (path); szDrive[3] = 0; @@ -904,6 +906,12 @@ GNUNET_DISK_directory_iterator_start (struct GNUNET_SCHEDULER_Handle *sched, di->callback = callback; di->callback_cls = callback_cls; di->directory = OPENDIR (dirName); + if (di->directory == NULL) + { + GNUNET_free (di); + callback (callback_cls, NULL, NULL, NULL); + return; + } di->dirname = GNUNET_strdup (dirName); di->priority = prio; GNUNET_DISK_directory_iterator_next (di, GNUNET_NO); diff --git a/src/util/getopt.c b/src/util/getopt.c index 82d0baebd..63caa0346 100644 --- a/src/util/getopt.c +++ b/src/util/getopt.c @@ -847,6 +847,7 @@ GN_getopt_internal (argc, argv, optstring, longopts, longind, long_only) /* Test all long options for either exact match or abbreviated matches. */ + if (longopts != NULL) for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 7079e2fef..54ac001f9 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -55,32 +55,31 @@ static char * get_path_from_proc_maps () { char fn[64]; - char *line; - char *dir; + char line[1024]; + char dir[1024]; FILE *f; + char *lgu; - GNUNET_snprintf (fn, 64, "/proc/%u/maps", getpid ()); - line = GNUNET_malloc (1024); - dir = GNUNET_malloc (1024); + GNUNET_snprintf (fn, + sizeof(fn), + "/proc/%u/maps", + getpid ()); f = fopen (fn, "r"); - if (f != NULL) + if (f == NULL) + return NULL; + while (NULL != fgets (line, sizeof(line), f)) { - while (NULL != fgets (line, 1024, f)) - { - if ((1 == sscanf (line, - "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", - dir)) && (NULL != strstr (dir, "libgnunetutil"))) - { - strstr (dir, "libgnunetutil")[0] = '\0'; - fclose (f); - GNUNET_free (line); - return dir; - } - } - fclose (f); + if ((1 == sscanf (line, + "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", + dir)) && + (NULL != (lgu = strstr (dir, "libgnunetutil")))) + { + lgu[0] = '\0'; + fclose (f); + return GNUNET_strdup (dir); + } } - GNUNET_free (dir); - GNUNET_free (line); + fclose (f); return NULL; } @@ -91,13 +90,13 @@ static char * get_path_from_proc_exe () { char fn[64]; - char *lnk; - size_t size; + char lnk[1024]; + ssize_t size; - GNUNET_snprintf (fn, 64, "/proc/%u/exe", getpid ()); - lnk = GNUNET_malloc (1024); - size = readlink (fn, lnk, 1023); - if ((size == 0) || (size >= 1024)) + GNUNET_snprintf (fn, + sizeof(fn), "/proc/%u/exe", getpid ()); + size = readlink (fn, lnk, sizeof (lnk)-1); + if ((size == 0) || (size >= sizeof(lnk)-1)) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); GNUNET_free (lnk); @@ -113,7 +112,7 @@ get_path_from_proc_exe () return NULL; } lnk[size] = '\0'; - return lnk; + return GNUNET_strdup (lnk); } #endif @@ -124,16 +123,15 @@ get_path_from_proc_exe () static char * get_path_from_module_filename () { - char *path; + char path[4097]; char *idx; - path = GNUNET_malloc (4097); - GetModuleFileName (NULL, path, 4096); + GetModuleFileName (NULL, path, sizeof(path)-1); idx = path + strlen (path); while ((idx > path) && (*idx != '\\') && (*idx != '/')) idx--; *idx = '\0'; - return path; + return GNUNET_strdup (path); } #endif