Commit Graph

9 Commits

Author SHA1 Message Date
Jan Höppner
cf39f26dee dasdinfo: Replace strncpy() with util_strlcpy()
Copy strings correctly by using util_strlcpy() over strncpy() and get
rid of the following GCC8 compile warning:

In function ‘dinfo_extract_dev’,
    inlined from ‘dinfo_get_dev_from_blockdev’ at dasdinfo.c:365:6:
dasdinfo.c:337:2: warning: ‘strncpy’ specified bound 80 equals
destination size [-Wstringop-trunc ation]
  strncpy(tmp, str, RD_BUFFER_SIZE);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2018-11-16 15:01:42 +01:00
Jan Höppner
e2d433bb10 dasdinfo: Display error messages on stderr output
Change all error messages from printf() to warnx().

While at it, remove the punctuation mark for some of the error messages.

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2018-11-16 15:01:41 +01:00
Rafael Fonseca
105b30a805 dasdinfo: Use libdasd for DASD ioctls
GitHub-ID: #19

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
Acked-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
2017-12-14 14:49:49 +01:00
Rafael Fonseca
70a7fc3e72 dasdinfo: Apply project's coding convention
GitHub-ID: #19

Signed-off-by: Rafael Fonseca <r4f4rfs@gmail.com>
Acked-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
2017-12-14 14:15:54 +01:00
Jan Höppner
e581fa3fea dasdinfo: Fix false line breaks
Commit 61b60baf57 ("dasdinfo: Fix GCC 7 overflow warning") erroneously
introduced line breaks to the UID (-u) output. To be consistent with the
extended uid ouput code, keep the newley indroduced line breaks and
remove the additional one from the string split above instead.

Fixes: 61b60baf57 ("dasdinfo: Fix GCC 7 overflow warning")
Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-12-06 16:00:16 +01:00
Jan Höppner
1261105fe2 dasdinfo: Fix truncation warning
Commit 3c80f7e025 ("dasdinfo: fix buffer overflow warning") changed a
sprintf call to snprintf to avoid a buffer overflow warning. However,
GCC 7 now warns about a potential truncation with snprintf:

dasdinfo.c: In function 'main':
dasdinfo.c:577:18: warning: '%s' directive output may be truncated
writing up to 255 bytes into a region of size 69 [-Wformat-truncation=]
      "/sys/block/%s/device/uid", dir_entry->d_name);
                  ^~
dasdinfo.c:576:4: note: 'snprintf' output between 23 and 278 bytes into
a destination of size 80
    snprintf(*uidfile, RD_BUFFER_SIZE,
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      "/sys/block/%s/device/uid", dir_entry->d_name);
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We could get around this by increasing the buffer. Though, the current
buffer size is already plenty and we know better anyway.
Avoid the warning by simply checking the return value of snprintf and
display an error in case data was truncated nonetheless.

Fixes: 3c80f7e025 ("dasdinfo: fix buffer overflow warning")
Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-10-18 16:58:49 +02:00
Stefan Haberland
3c80f7e025 dasdinfo: fix buffer overflow warning
Fix a possible buffer overflow.
The buffer overflow is only theoretical since the device name is max
8 characters in length.

This fixes following gcc 7 warning:

 dasdinfo.c: In function 'main':
 dasdinfo.c:576:33: warning: '%s' directive writing up to 255 bytes into a
                                   region of size 69 [-Wformat-overflow=]
     sprintf(*uidfile,"/sys/block/%s/device/uid",
                                  ^~
 In file included from /usr/include/stdio.h:862:0,
                  from dasdinfo.c:15:
 /usr/include/bits/stdio2.h:33:10: note: '__builtin___sprintf_chk' output
                    between 23 and 278 bytes into a destination of size 80
    return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        __bos (__s), __fmt, __va_arg_pack ());
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-09-22 16:52:45 +02:00
Jan Höppner
61b60baf57 dasdinfo: Fix GCC 7 overflow warning
With GCC 7 we get the following warning as a potential overflow might
happen, if d_name gets too big:

dasdinfo.c: In function 'main':
dasdinfo.c:611:37: warning: '%s' directive writing up to 255 bytes into
  a region of size 69 [-Wformat-overflow=]
   sprintf(sys_dev_path, "/sys/block/%s/dev", dir_entry->d_name);
                                     ^~
dasdinfo.c:611:3: note: 'sprintf' output between 16 and 271 bytes into a
  destination of size 80
   sprintf(sys_dev_path, "/sys/block/%s/dev", dir_entry->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This could be fixed by simply increasing the buffer size. However, there
is a little bit more to it and the way files are currently read can be
simplified.
Do this by using the libutil functions to read files and clean up a
little along the way.

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-09-15 05:07:42 +02:00
Michael Holzheu
b627b8d8e1 Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version.

Changes on top of s390-tools-1.39.0:

 - Add MIT license to all source files
 - Add LICENSE file
 - Transform REAMDE to README.md (markdown)
 - Add AUTHORS.md file
 - Add CONTRIBUTING.md file
 - Move changelog from README to CHANGELOG.md file

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-08-21 10:55:40 +02:00