mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Using inappropriate sizes for snprintf() leads to the following compile
warnings:
dfi_s390mv.c: In function ‘dev_from_busid’:
dfi_s390mv.c:116:34: warning: ‘/online’ directive output may be
truncated writing 7 bytes into a region of size between 1 and 4096
[-Wformat-truncation=]
snprintf(tmp_file, PATH_MAX, "%s/online", dev_file);
^~~~~~~
dfi_s390mv.c:116:2: note: ‘snprintf’ output between 8 and 4103 bytes
into a destination of size 4096
snprintf(tmp_file, PATH_MAX, "%s/online", dev_file);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dfi_s390mv.c:143:35: warning: ‘%s’ directive output may be truncated
writing up to 255 bytes into a region of size between 0 and 4095
[-Wformat-truncation=]
snprintf(tmp_file, PATH_MAX, "%s/%s/dev", dev_file, direntp->d_name);
^~
dfi_s390mv.c:143:2: note: ‘snprintf’ output between 6 and 4356 bytes
into a destination of size 4096
snprintf(tmp_file, PATH_MAX, "%s/%s/dev", dev_file, direntp->d_name);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A simple fix would be to use different suitable fixed sizes for tmp_file
and dev_file. However, the code can be improved here a little.
Use the libutil function util_path_sysfs() to build the sysfs path
string. This is more robust, as the function will figure out the correct
mount point of the sysfs. util_path_sysfs() will also terminate
execution, if no sysfs mount point could be found. That means, we can
get rid of check_sysfs().
Furthermore, the two variables (tmp_file, dev_file) can be combined to
one. Also, check the return value of open() and act accordingly.
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
/*
|
|
* zgetdump - Tool for copying and converting System z dumps
|
|
*
|
|
* S390 multi-volume dump input format common structures
|
|
*
|
|
* Copyright IBM Corp. 2001, 2018
|
|
*
|
|
* s390-tools is free software; you can redistribute it and/or modify
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
*/
|
|
#ifndef DFI_S390MV_H
|
|
#define DFI_S390MV_H
|
|
|
|
#include "lib/zt_common.h"
|
|
|
|
#define SYSFS_BUSDIR "bus/ccw/devices"
|
|
#define MAX_VOLUMES 32
|
|
|
|
/*
|
|
* Parameter for DASD multi-volume dump
|
|
*/
|
|
struct vol_parm {
|
|
u16 devno;
|
|
u32 start_blk;
|
|
u32 end_blk;
|
|
u8 blk_size;
|
|
u8 end_sec;
|
|
u8 num_heads;
|
|
} __attribute__ ((packed));
|
|
|
|
struct vol_parm_table {
|
|
u64 timestamp;
|
|
u16 vol_cnt;
|
|
struct vol_parm vol_parm[MAX_VOLUMES];
|
|
u8 ssid[MAX_VOLUMES];
|
|
} __attribute__ ((packed));
|
|
|
|
/*
|
|
* Device signature
|
|
*/
|
|
enum dev_sign {
|
|
SIGN_INVALID = 0, /* No dumper installed */
|
|
SIGN_VALID = 1, /* dumper installed, but volume not used */
|
|
SIGN_ACTIVE = 2, /* dumper installed and volume userd */
|
|
};
|
|
|
|
static char *dev_sign_str[] = {"invalid", "valid", "active"};
|
|
#define dev_sign_str(x) (dev_sign_str[x])
|
|
|
|
/*
|
|
* Device status
|
|
*/
|
|
enum dev_status {
|
|
DEV_ONLINE = 0,
|
|
DEV_OFFLINE = 1,
|
|
DEV_UNDEFINED = 2,
|
|
};
|
|
|
|
static char *dev_status_str[] = {"online", "offline", "undefined"};
|
|
#define dev_status_str(x) (dev_status_str[x])
|
|
|
|
#endif /* DFI_S390MV_H */
|