summaryrefslogtreecommitdiff
path: root/source3/client
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-06-14 21:36:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:17:26 -0500
commita1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 (patch)
tree14c15c8333572c5a2e089611ee61d03010a9d2b4 /source3/client
parent2b99951e7511d0ec2d928c06b05fe22b7b6572d1 (diff)
downloadsamba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.tar.gz
samba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.tar.bz2
samba-a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1.zip
r16230: Fix Klocwork #861 and others. localtime and asctime
can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc)
Diffstat (limited to 'source3/client')
-rw-r--r--source3/client/client.c26
-rw-r--r--source3/client/clitar.c2
-rw-r--r--source3/client/smbctool.c30
3 files changed, 45 insertions, 13 deletions
diff --git a/source3/client/client.c b/source3/client/client.c
index 1fbee70645..aa25d9aba5 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -379,7 +379,7 @@ static void display_finfo(file_info *finfo)
finfo->name,
attrib_string(finfo->mode),
(double)finfo->size,
- asctime(localtime(&t)));
+ time_to_asc(&t));
dir_total += finfo->size;
}
}
@@ -2111,6 +2111,7 @@ static int cmd_stat(void)
fstring mode_str;
SMB_STRUCT_STAT sbuf;
struct cli_state *targetcli;
+ struct tm *lt;
pstring targetname;
if (!SERVER_HAS_UNIX_CIFS(cli)) {
@@ -2165,13 +2166,28 @@ static int cmd_stat(void)
(unsigned int)sbuf.st_uid,
(unsigned int)sbuf.st_gid);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
+ lt = localtime(&sbuf.st_atime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Access: %s\n", mode_str);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
+ lt = localtime(&sbuf.st_mtime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Modify: %s\n", mode_str);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
+ lt = localtime(&sbuf.st_ctime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Change: %s\n", mode_str);
return 0;
@@ -2339,7 +2355,7 @@ static int cmd_newer(void)
if (ok && (sys_stat(buf,&sbuf) == 0)) {
newer_than = sbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
- asctime(localtime(&newer_than))));
+ time_to_asc(&newer_than)));
} else {
newer_than = 0;
}
diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index a7bc4bfde3..14c28acfc5 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -1641,7 +1641,7 @@ int tar_parseargs(int argc, char *argv[], const char *Optarg, int Optind)
if (sys_stat(argv[Optind], &stbuf) == 0) {
newer_than = stbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
- asctime(localtime(&newer_than))));
+ time_to_asc(&newer_than)));
newOptind++;
Optind++;
} else {
diff --git a/source3/client/smbctool.c b/source3/client/smbctool.c
index ba095aee84..5b21d195b7 100644
--- a/source3/client/smbctool.c
+++ b/source3/client/smbctool.c
@@ -445,7 +445,7 @@ static void display_finfo(file_info *finfo)
finfo->name,
attrib_string(finfo->mode),
(double)finfo->size,
- asctime(localtime(&t)));
+ time_to_asc(&t));
dir_total += finfo->size;
}
}
@@ -458,7 +458,7 @@ static void display_stat(char *name, struct stat *st)
{
time_t t = st->st_mtime;
pstring time_str;
- pstrcpy(time_str, asctime(localtime(&t)));
+ pstrcpy(time_str, time_to_asc(&t));
time_str[strlen(time_str)-1] = 0;
d_printf("> %-30s", name);
d_printf("%10.10s %8.0f %s\n", *mode_t_string(st->st_mode), (double)st->st_size, time_str);
@@ -2303,6 +2303,7 @@ static int cmd_stat(void)
fstring mode_str;
SMB_STRUCT_STAT sbuf;
struct cli_state *targetcli;
+ struct tm *lt;
pstring targetname;
if (!SERVER_HAS_UNIX_CIFS(cli)) {
@@ -2357,15 +2358,30 @@ static int cmd_stat(void)
(unsigned int)sbuf.st_uid,
(unsigned int)sbuf.st_gid);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
+ lt = localtime(&sbuf.st_atime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Access: %s\n", mode_str);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
+ lt = localtime(&sbuf.st_mtime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Modify: %s\n", mode_str);
- strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
+ lt = localtime(&sbuf.st_ctime);
+ if (lt) {
+ strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
+ } else {
+ fstrcpy(mode_str, "unknown");
+ }
d_printf("Change: %s\n", mode_str);
-
+
return 0;
}
@@ -2538,7 +2554,7 @@ static int cmd_newer(void)
if (ok && (sys_stat(buf,&sbuf) == 0)) {
newer_than = sbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
- asctime(localtime(&newer_than))));
+ time_to_asc(&newer_than)));
} else {
newer_than = 0;
}