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);
+ }
}
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);
+ }
}
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))
{
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))
{
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;
}
}
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)
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);
}
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);
}
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))
struct GNUNET_FS_ProgressInfo pi;
struct GNUNET_FS_DownloadContext *dc;
- if ( (sr != NULL) &&
+ if ( (sr == NULL) ||
(sr->download != NULL) )
{
GNUNET_break (0);
&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),
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))
{
&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),
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,
{
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;
}
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;
_("Could not initialize `%s' subsystem.\n"),
"FS");
GNUNET_FS_uri_destroy (uri);
- GNUNET_FS_stop (ctx);
ret = 1;
return;
}
}
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;
*
* @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)
*/
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++)
{
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))
{
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,
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)
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))))
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")))
{
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")))
{
}
/* 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);
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)
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));
char *path;
path = GNUNET_STRINGS_filename_expand (part);
+ if (path == NULL)
+ return -1;
memcpy (szDrive, path, 3);
GNUNET_free (path);
szDrive[3] = 0;
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);
/* 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))
{
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;
}
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);
return NULL;
}
lnk[size] = '\0';
- return lnk;
+ return GNUNET_strdup (lnk);
}
#endif
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