Rest api upload add control-m character

When I upload the plain text file using curl or python to restpi. It adds the control-M character in the end.

curl -X POST -F file=@/etc/sudoers --user “user:pwd” https://root:52311/api/upload

see the size of sudoers in linux host.
image

And when it uploaded to root server.
It added 1byte extra ( control- M).

image

becuase of control-M character the sudoers wont’ work.

Hello, I did a quick test but can’t reproduce your problem. testing the curl command on a RHEL box:
curl -ku User:password --form upload=@/etc/“sudoers” https://nc147440:52311/api/upload

The server is a windows machine, the file is correctly uploaded into the upload dir at:
C:\Program Files (x86)\BigFix Enterprise\BES Server\wwwrootbes\Uploads\7f8136e115bc8877afdda1cb9c357da7ecdbb8d2\sudoers

The last line of the file contains the HEX OA which is also in the original file on my RHEL machine, the “hexdump -C ./sudoers” command shows it:

00000f90 69 72 20 2f 65 74 63 2f 73 75 64 6f 65 72 73 2e |ir /etc/sudoers.|
00000fa0 64 0a |d.|

Yes that behavior looks like the file was edited on a Windows machine…Windows uses the CR/LF combination for an end-of-line ( %0d%0a ) where UNIX uses a single linefeed character ( %0a ).

If a DOS text file with cr/LF is opened on some UNIX editors like vi, the CR/LF combination is displayed as ^M

It’s likely your file was modified somewhere before you uploaded it. I haven’t seen curl do that, but perhaps someone opened in Notepad and saved it?

1 Like

I tar’d the file and uploaded to rest api to avoid this CTRL-M issue. I think some where in the root rest api is adding the additional carriage return. I have pushed the same sudoers via curl to linux hosts it works fine.