Commit 25a9c53b authored by Michal Privoznik's avatar Michal Privoznik

Resolve some compilation warnings

Some of the return values are not checked. This triggers
compilation warnings. But more importantly, we really should
check the return values as they are critical. Like if we
successfully written data into a pipe or read it back.
Signed-off-by: 's avatarMichal Privoznik <mprivozn@redhat.com>
parent a4219e4b
......@@ -2283,6 +2283,7 @@ PHP_FUNCTION(libvirt_image_create)
long long size;
char *size_str;
int size_str_len;
int cmdRet;
if (LIBVIRT_G(image_path_ini))
path = strdup( LIBVIRT_G(image_path_ini) );
......@@ -2316,9 +2317,9 @@ PHP_FUNCTION(libvirt_image_create)
snprintf(cmd, sizeof(cmd), "%s create -f %s %s %dM > /dev/null", qemu_img_cmd, format, fpath, size);
DPRINTF("%s: Running '%s'...\n", PHPFUNC, cmd);
system(cmd);
cmdRet = system(cmd);
if (access(fpath, F_OK) == 0) {
if (WEXITSTATUS(cmdRet) == 0 && access(fpath, F_OK) == 0) {
RETURN_TRUE;
}
else {
......@@ -4067,11 +4068,14 @@ PHP_FUNCTION(libvirt_domain_get_screenshot_api)
if (bin) {
char tmp[4096] = { 0 };
char fileNew[1024] = { 0 };
int exitStatus;
snprintf(fileNew, sizeof(fileNew), "%s.png", file);
snprintf(tmp, sizeof(tmp), "%s %s %s > /dev/null 2> /dev/null", bin, file, fileNew);
system(tmp);
exitStatus = system(tmp);
unlink(file);
if (WEXITSTATUS(exitStatus) != 0)
RETURN_FALSE;
add_assoc_string_ex(return_value, "file", 5, fileNew, 1);
add_assoc_string_ex(return_value, "mime", 5, "image/png", 1);
......@@ -4627,7 +4631,8 @@ PHP_FUNCTION(libvirt_connect_get_nic_models)
array_init(return_value);
while (!feof(fp)) {
memset(cmd, 0, sizeof(cmd));
fgets(cmd, sizeof(cmd), fp);
if (!fgets(cmd, sizeof(cmd), fp))
break;
if ((tmp = strstr(cmd, "Supported NIC models:")) != NULL) {
tmp = strstr(tmp, ":") + 2;
......@@ -4700,7 +4705,8 @@ PHP_FUNCTION(libvirt_connect_get_soundhw_models)
array_init(return_value);
while (!feof(fp)) {
memset(cmd, 0, sizeof(cmd));
fgets(cmd, sizeof(cmd), fp);
if (!fgets(cmd, sizeof(cmd), fp))
break;
if (strncmp(cmd, "Valid ", 6)== 0) {
inFunc = 1;
......@@ -5356,8 +5362,10 @@ PHP_FUNCTION(libvirt_domain_disk_add)
tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
if (tmp != NULL) {
free(tmp);
asprintf(&tmp, "Domain already has image <i>%s</i> connected", img);
set_error(tmp TSRMLS_CC);
if (asprintf(&tmp, "Domain already has image <i>%s</i> connected", img) < 0)
set_error("Out of memory" TSRMLS_CC);
else
set_error(tmp TSRMLS_CC);
goto error;
}
......@@ -5369,8 +5377,10 @@ PHP_FUNCTION(libvirt_domain_disk_add)
tmp = get_string_from_xpath(xml, newXml, NULL, &retval);
if (tmp != NULL) {
free(tmp);
asprintf(&tmp, "Domain already has device <i>%s</i> connected", dev);
set_error(tmp TSRMLS_CC);
if (asprintf(&tmp, "Domain already has device <i>%s</i> connected", dev) < 0)
set_error("Out of memory" TSRMLS_CC);
else
set_error(tmp TSRMLS_CC);
goto error;
}
......@@ -5447,8 +5457,10 @@ PHP_FUNCTION(libvirt_domain_disk_remove)
}
tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
if (!tmp) {
asprintf(&tmp, "Device <i>%s</i> is not connected to the guest", dev);
set_error(tmp TSRMLS_CC);
if (asprintf(&tmp, "Device <i>%s</i> is not connected to the guest", dev) < 0)
set_error("Out of memory" TSRMLS_CC);
else
set_error(tmp TSRMLS_CC);
goto error;
}
......@@ -5530,8 +5542,10 @@ PHP_FUNCTION(libvirt_domain_nic_add)
tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
if (tmp) {
free(tmp);
asprintf(&tmp, "Domain already has NIC device with MAC address <i>%s</i> connected", mac);
set_error(tmp TSRMLS_CC);
if (asprintf(&tmp, "Domain already has NIC device with MAC address <i>%s</i> connected", mac) < 0)
set_error("Out of memory" TSRMLS_CC);
else
set_error(tmp TSRMLS_CC);
goto error;
}
......@@ -5617,8 +5631,10 @@ PHP_FUNCTION(libvirt_domain_nic_remove)
tmp = get_string_from_xpath(xml, xpath, NULL, &retval);
if (!tmp) {
free(tmp);
asprintf(&tmp, "Domain has no such interface with mac %s", mac);
set_error(tmp TSRMLS_CC);
if (asprintf(&tmp, "Domain has no such interface with mac %s", mac) < 0)
set_error("Out of memory" TSRMLS_CC);
else
set_error(tmp TSRMLS_CC);
goto error;
}
......
......@@ -179,10 +179,11 @@ void socket_read(int sfd, long length)
length = 0;
}
if (length)
read(sfd, bigbuf, length);
DPRINTF("%s: All bytes read\n", PHPFUNC);
if (length &&
read(sfd, bigbuf, length) != length)
DPRINTF("%s: not all byes read\n", PHPFUNC);
else
DPRINTF("%s: All bytes read\n", PHPFUNC);
}
/*
......@@ -221,7 +222,8 @@ int socket_read_and_save(int sfd, char *fn, long length)
for (i = 0; i < len; i += 4)
SWAP2_BYTES_ENDIAN(1, bigbuf[i+1], bigbuf[i+2]);
write(fd, bigbuf, len);
if (write(fd, bigbuf, len) != len)
DPRINTF("%s: unable to write to %d", PHPFUNC, fd);
length -= len;
if (length < 0)
......@@ -234,10 +236,12 @@ int socket_read_and_save(int sfd, char *fn, long length)
for (i = 0; i < len; i += 4)
SWAP2_BYTES_ENDIAN(1, bigbuf[i+1], bigbuf[i+2]);
write(fd, bigbuf, len);
if (write(fd, bigbuf, len) != len)
DPRINTF("%s: unable to write to %d", PHPFUNC, fd);
}
ftruncate(fd, orig_len);
if (ftruncate(fd, orig_len) < 0)
DPRINTF("%s: Unable to truncate %d", PHPFUNC, fd);
close(fd);
......
......@@ -635,8 +635,8 @@ int vnc_raw_to_bmp(char *infile, char *outfile, int width, int height)
if (fd2 == -1)
return -EPERM;
write(fd2, "BM", 2);
if (write(fd2, &fBMP, hsize) < 0)
if (write(fd2, "BM", 2) < 0 ||
write(fd2, &fBMP, hsize) < 0)
perror("Error on write");
ix = 0;
......@@ -666,7 +666,8 @@ int vnc_raw_to_bmp(char *infile, char *outfile, int width, int height)
for (ix = start; ix < end; ix++) {
UINT32STR(tbuf, pixels[ix]);
write(fd2, tbuf, 4);
if (write(fd2, tbuf, 4) < 0)
perror("Error on write");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment